【发布时间】:2012-01-05 20:22:01
【问题描述】:
我正在尝试在 word 文档中添加文件
application.Selection.InsertFile(file);
但它会导致异常
COMException: The document name or path is not valid
然后保存
document.SaveAs(path);
然后我得到了异常
The object invoked has disconnected from its clients. (Exception HRESULT: 0x80010108 (RPC_E_DISCONNECTED))
完全相同的代码在从 Visual Studio 运行时有效。 异常仅在我尝试从 IIS 运行时发生。
可能与某些权限有关吗?我已授予Everyone、ISUSR、Network、Network Service、System、Administrators... 的完全控制权限...而且我还尝试通过管理员帐户使用 Impersonate。
如何修复它以便在我从 IIS 运行时可以正常工作?
这是我用来操作文档的类:http://pastebin.com/yB2s0jn4
这就是我的称呼
using (var doc = new HtmlWordDocument(outFile))
{
// calls Selection.InsertFile( file )
doc.WriteContent(tempFile);
// calls document.SaveAs()
doc.Save();
}
【问题讨论】:
-
您是否验证了文件安全和 IIS AppPool 的安全帐户?
-
@Simon 我向
Everyone添加了对文件文件夹的完全控制权限,并配置了 IIS 应用程序池以使用我的管理员凭据。什么都没有改变... -
tempFile 文件夹怎么样?
-
你好,我也有同样的问题,你解决了吗? :((
标签: c# ms-word ms-office com-interop