将 byte[] 作为文件打开,而不先将其实际保存为文件
打开以 byte[] 形式存储在数据库中的 Word 文件的最佳方法是什么?
我必须将一些文档存储在 Access 数据库中(Word 文件、2003 及更高版本),并存储在严格通过 CD 运行的应用程序上。不幸的是,它们必须位于数据库中,并且不能松散地存储在文件夹中。我将它们存储为 OLE 对象,并且可以像 byte[] 一样读写它们。
但是,我不知道在 Word 中重新打开这些文档的最佳方法。现在,我正在使用 FileStream 在某处重新创建文件,然后发出 System.Diagnostics.Process.Start(filename) 来打开它。这将用于政府计算机,有时可能有一些奇怪的安全规则,所以我不知道这是否是最好的方法。
是否可以打开以前存储为 byte[] 的文件而不使用保存到硬盘驱动器的任何中间文件?我知道他们至少会有 Word 2003,所以我愿意使用 Word 互操作。
感谢您的任何意见!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑你是否能够在内存中向 Word 提供一个文件,而无需将其保存到至少 RAMDisk 或类似的东西中。
为什么不在使用 Word 打开文件之前使用系统临时文件夹或 GetTempFile() 方法将字节数组写入文件,然后在完成后清理临时文件?
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?