【发布时间】:2012-07-19 14:07:35
【问题描述】:
我正在尝试获取仍在 Word 中打开的活动 Word 文档的 base64 表示 并在 ReadAllBytes() 中收到以下错误:
进程无法访问它正在被另一个进程使用的文件“文件路径”
public string GetEncodedTemplate()
{
//Convert a Word document's base64 representation
string base64 = String.Empty;
_application.ActiveDocument.Save();
string docPath = _application.ActiveDocument.FullName;
byte[] binarydata = File.ReadAllBytes(docPath);
base64 = System.Convert.ToBase64String(binarydata, 0, binarydata.Length);
return base64;
}
我确实了解发生错误是因为指定的文档仍在 Word 中打开, 我的问题是 - 是否仍然有可能在不求助于保存到临时文件的情况下获得文档的 base64 表示?
我正在使用 C# .NET 4.0 和 MS Office 2010
【问题讨论】: