Opening byte[] as a file without actually saving i

2019-04-11 05:32发布

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!

1条回答
太酷不给撩
2楼-- · 2019-04-11 06:12

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();
查看更多
登录 后发表回答