Show a .doc, .pdf or .txt

P

Peter K

Hi

In my windows application I have a byte array which could for example hold
the binary data for a pdf document or a word document or a .txt document. I
know the type of data - eg .pdf or .doc or .txt etc.

How do I activate the Windows "designated application" for handling the
file type to show the binary data I have? For example, if I have binary
data for a .doc, how do I activate Microsoft Word (or whatever application
is configured in Windows to handle .doc files) to show the data as a doc
file?


Thanks,
Peter
 
N

Nicholas Paldino [.NET/C# MVP]

Peter,

In this case, you are going to have to save the file to disk (in a
temporary file) and then use the Process class, passing the name of the
temporary file (with the correct extension) to the Start method. The OS
will take over from there, displaying the designated application.

You can then call the WaitForExit method on the Process instance, and
when that line of code returns, you can delete your temporary file.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

You need to save it to a temp file ( using Path.GetTempFileName ) and adding
the extension you know it should have.

Then simply yse Process.Start to have the default program execute it.
 
P

Peter K

In my windows application I have a byte array which could for example
hold the binary data for a pdf document or a word document or a .txt
document. I know the type of data - eg .pdf or .doc or .txt etc.

How do I activate the Windows "designated application" for handling
the file type to show the binary data I have? For example, if I have
binary data for a .doc, how do I activate Microsoft Word (or whatever
application is configured in Windows to handle .doc files) to show the
data as a doc file?

Hi - thanks for the answers - it turned out to be very easy, as the binary
data was to be written to a file anyway, so there was no need to create a
temporary file which had to be deleted...

Thanks,
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top