Rod
Rod

Reputation: 15455

opening pdf file in console app

Is there a way to have my console app open my PDF file (in my default application for PDFs) given a byte array?

Upvotes: 4

Views: 6635

Answers (1)

Dirk Vollmar
Dirk Vollmar

Reputation: 176189

If you want to open the PDF in the default application you will have to save it first to a temporary location:

byte[] buffer = GetPdfData();

// save to temp file
string path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()+".pdf");
File.WriteAllBytes(path, buffer);

// open in default PDF application
Process process = Process.Start(path);
process.WaitForExit();

// clean up temp file
File.Delete(path);

Upvotes: 14

Related Questions