使用“InsertFile”并从 IIS 上的网站保存文件

发布于 2024-12-17 21:24:26 字数 1119 浏览 0 评论 0 原文

我正在尝试在 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 ServiceSystem 完全控制权限code>, Administrators... 我还尝试使用模拟管理员帐户。

如何修复它,以便在从 IIS 运行时它可以正常工作?


这是我为操作文档而创建的类:http://pastebin.com/yB2s0jn4

这就是我的称呼

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

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

I am trying to add a file on a word document

application.Selection.InsertFile(file);

But it causes the exception

COMException: The document name or path is not valid

And then save it

document.SaveAs(path);

But then I get the exception

The object invoked has disconnected from its clients. (Exception HRESULT: 0x80010108 (RPC_E_DISCONNECTED))

The exact same code works when running from Visual Studio. The exception only happens when I try to run from IIS.

Could it be related to some permission? I have given full control permissions to Everyone, ISUSR, Network, Network Service, System, Administrators... And I also tried to use Impersonate with an administrator account.

How can I fix it so it will work when I run from IIS?


Here is the class I made to manipulate the doc: http://pastebin.com/yB2s0jn4

And here is how I am calling it

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

爱人如己 2024-12-24 21:24:26

您是否尝试过模拟(如何在 ASP.NET 应用程序中实现模拟)?像下面这样:

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();

Have you tried impersonation (How to implement impersonation in an ASP.NET application)? like below:

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();
昔梦 2024-12-24 21:24:26

您需要启用 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

you need IISADMIN service enabled but it's not istalled by default, this service will permit to connect IIS to more OS resources

Check this...

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

and this...

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

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