Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opening pdf file in console app

Tags:

c#

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

like image 722
Rod Avatar asked Dec 13 '22 18:12

Rod


1 Answers

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);
like image 125
Dirk Vollmar Avatar answered Dec 23 '22 13:12

Dirk Vollmar