Jerry Nixon @Work: Save Bytes and Run

Jerry Nixon on Windows

Tuesday, July 26, 2011

Save Bytes and Run

Ever wonder how to save a byte[] array and run it?

This is the code I use to launch a PDF files I have as byte[] arrays.

    // identify temporary file path, save
    var _Folder = System.IO.Path.GetTempPath();
    var _File = string.Format("{0}.PDF"Guid.NewGuid());
    var _Path = System.IO.Path.Combine(_Folder, _File);
    System.IO.File.WriteAllBytes(_Path, bytes);
 

    // let's hope Adobe reader is installed!
    System.Diagnostics.Process.Start(_Path);