开发者

Display a file from a byte[] or stream

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 th开发者_如何学运维e 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?


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


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜