我有整个MS Word文件本身保存在一个字节数组中。我想以与文件系统上相同的方式加载它,但要尽量减少对Microsoft.Office.Interop.Word的使用,因为在执行.Open(args[])
部分时速度非常缓慢。
我有整个MS Word文件本身保存在一个字节数组中。我想以与文件系统上相同的方式加载它,但要尽量减少对Microsoft.Office.Interop.Word的使用,因为在执行.Open(args[])
部分时速度非常缓慢。
尝试这个....
byte[] bte = File.ReadAllBytes("E:\\test.doc"); // Put the Reading file
File.WriteAllBytes(@"E:\\test1.doc", bte); // Same contents you will get in byte[] and that will be save here
byte[]
保留在内存中,而无需将文件写入磁盘? - Adam// byte[] fileBytes = getFileBytesFromDB();
var tmpFile = Path.GetTempFileName();
File.WriteAllBytes(tmpFile, fileBytes);
Application app = new word.Application();
Document doc = app.Documents.Open(filePath);
// .. do your stuff here ...
doc.Close();
app.Quit();
byte[] newFileBytes = File.ReadAllBytes(tmpFile);
File.Delete(tmpFile);
如需更多信息,请访问我的博客,阅读此文章。
方法public static byte[] ReadAllBytes(
string path
)
将所有文件信息返回到一个字节数组中。您不必担心流,因为MSDN文档说:
"给定文件路径,此方法打开文件,将文件内容读入字节数组,然后关闭文件。"
如果您想要更多信息,请查看此链接。