将 byte[] 作为文件打开,而不先将其实际保存为文件

发布于 2024-09-08 10:15:46 字数 453 浏览 3 评论 0原文

打开以 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

念﹏祤嫣 2024-09-15 10:15:46

我怀疑你是否能够在内存中向 Word 提供一个文件,而无需将其保存到至少 RAMDisk 或类似的东西中。

为什么不在使用 Word 打开文件之前使用系统临时文件夹或 GetTempFile() 方法将字节数组写入文件,然后在完成后清理临时文件?

  string fullPathToATempFile = System.IO.Path.GetTempFileName();
// or
  string tempDirPath = System.IO.Path.GetTempPath();

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文