Friday, February 4, 2011

Opening a file stored in a database in .NET

I'm storing a Word document in a SQL Server 2005 database in a varbinary(max) column. Is there a way to open this document from a VB.NET Windows Forms application without serialising to a file first (i.e. directly from the byte array I've read from the database)?

  • Not really. You need to treat it like an e-mail attachment, where the file is generally copied to a temp folder that is cleaned out periodically.

  • Depends on what's reading it. If it's Word, you'll probably have to serialize to a file, but if it's a function or library that can take an IO.Stream then you could wrap a new MemoryStream around the byte array and pass that.

0 comments:

Post a Comment