【问题标题】:Using `InsertFile` and saving the file from website on IIS使用“InsertFile”并将文件从网站保存到 IIS
【发布时间】: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 运行时发生。

可能与某些权限有关吗?我已授予EveryoneISUSRNetworkNetwork ServiceSystemAdministrators... 的完全控制权限...而且我还尝试通过管理员帐户使用 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


【解决方案1】:

您是否尝试过模拟 (How to implement impersonation in an ASP.NET application)?如下:

System.Security.Principal.WindowsImpersonationContext impersonationContext;
impersonationContext = 
    ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();

    using (var doc = new HtmlWordDocument(outFile))
    {
        // calls Selection.InsertFile( file )
        doc.WriteContent(tempFile);

        // calls document.SaveAs()
        doc.Save();
    }

impersonationContext.Undo();

【讨论】:

    【解决方案2】:

    您需要启用 IISADMIN 服务,但默认未安装,此服务将允许将 IIS 连接到更多操作系统资源

    检查一下...

    https://social.msdn.microsoft.com/Forums/en-US/28ddf643-0f9b-46e6-a8c5-a83f5a36c361/not-able-to-see-iis-admin-service-in-windows-server-2008-r2?forum=netfxbcl

    还有这个……

    https://support.microsoft.com/en-us/kb/555134

    【讨论】:

      猜你喜欢
      • 2011-07-25
      • 1970-01-01
      • 1970-01-01
      • 2013-05-18
      • 1970-01-01
      • 2021-10-15
      • 2020-08-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多