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

萝らか妹 提交于 2019-12-21 20:19:37

问题


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:


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();


来源:https://stackoverflow.com/questions/3199674/opening-byte-as-a-file-without-actually-saving-it-as-a-file-first

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!