Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening byte[] as a file without actually saving it as a file first

What is the best way to open a Word file that was stored as a byte[] in a database?

I have to store some documents in an Access database - Word files, 2003 and up - on an application that is strictly run off of a CD. Unfortunately they have to be in the database and can't be stored loose in folders. I'm storing them as an OLE object, and I can read and write them just fine as a byte[].

However, I don't know the best way of getting these documents back open in Word. Right now I'm using a FileStream to recreate the file in somewhere and then shooting off a System.Diagnostics.Process.Start(filename) to get it to open. This is going to be used on government computers which can have some funky security rules sometimes, so I don't know if this is the best way.

Is it possible to open a file previously stored as a byte[] without using any intermediary file saved to the hard drive? I know they'll at least have Word 2003, so I'm open to using the Word interop.

Thanks for any input!

like image 907
Sodium Hydroxide Avatar asked Dec 06 '25 00:12

Sodium Hydroxide


1 Answers

I doubt you're going to be able to feed Word a file in memory without saving it to at least a RAMDisk or something wild like that.

Why not use the system temp folder or the GetTempFile() method to write the byte array to a file just before opening it using Word and then cleaning up the temp files when you're done?

  string fullPathToATempFile = System.IO.Path.GetTempFileName();
// or
  string tempDirPath = System.IO.Path.GetTempPath();
like image 178
Tahbaza Avatar answered Dec 07 '25 14:12

Tahbaza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!