Question

I've got a winforms app that stores the contents of files in a database. The stored files can be of just about any type (word, excel, PDF, text, image ...) the user can select just about any type of file to load.

The user can then query the database, find a file and then open it.

I've got no problems extracting the byte array from the database, as either a stream or a byte array.

Ideally I'd be able to display the file directly from a byte array or stream; at the moment I'm saving it as a temporary file and then opening that with:

Process.Start(fileName);

How can I display the file with the associated application either from any of the byte array or stream file?

Was it helpful?

Solution

In windows, your only option is to do exactly what you're doing. Outlook, Internet explorer, firefox, all do this

OTHER TIPS

Maybe you want to research a little bit on Memory Mapped File.

you can try to open the directory containing it, but it will be the same thing you're doing right now.. if the associated app is known by the OS, then there will be no problem..

If you store a filename in the DB along with the byte stream, you can determine the file type from the extension. There's two options in this case:

  1. Use the registry to determine what application to use. For more info on this, take a look at this conversation on bytes.com.
  2. P/Invoke SHGetFileInfo to determine what application to use.

NB: With both options you'll still need to write the file data to a temp file on disk in order to load it.

Personally, I'd think what you're doing is probably the easiest option, anyway (unless you'd like to provide custom viewers for certain file-types, etc)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top