Using `InsertFile` and saving the file from website on IIS

3

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();
}
c#
ms-word
ms-office
com-interop
asked on Stack Overflow Nov 24, 2011 by BrunoLM • edited Dec 4, 2011 by Jason Plank

2 Answers

0

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();
answered on Stack Overflow Nov 24, 2011 by MichaƂ Powaga
0

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

answered on Stack Overflow Jun 24, 2015 by Payedimaunt • edited Jun 24, 2015 by Payedimaunt

User contributions licensed under CC BY-SA 3.0