Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 952
  • Last Modified:

Converting Word Document using com at IIS using ASP.NET returns an error

Hi,

I developed a ASP.NET page that convert a word document to a HTML page.
This work fine at my development PC but at my server I get a message at the first line:
protected Microsoft.Office.Interop.Word.ApplicationClass objApp = new Microsoft.Office.Interop.Word.ApplicationClass(); reports:

Retrieving the COM class factory for component with CLSID
{000209FF-0000-0000-C000-000000000046} failed due to the following error:
80070005

Word ist installed right and also web.config reports no error:
<add assembly="Microsoft.Office.Interop.Word, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"/></assemblies>

Ok, I found many hints at the net and understand that's access rights issue.
However I'm not able to fix it...
People suggest to change the com access rights using dcomcnfg but I can't find any word settings there ...

The server system:
Windows 2008 Server
Framework 3.5
Office 2007

Maybe somebody here can help me to make this work and have a solution for?

Thanks

Andre
0
andre72
Asked:
andre72
  • 5
  • 2
1 Solution
 
Dhanasekaran SengodanCommented:
The process identity of application is running under IIS and the one of application is running from Visual Studio are difference. The IIS account is "ASPNET" or "NETWORK SERVICE basing on IIS version. In this case, please make sure this account has permission to access the word COM component.

You can try the following steps to add account:

•  Run dcomcnfg to enter Component Services window.
•  Expand Component Services > Computers > My Computer > DCOM Config
•  Right click Windows Management and Instrumentation, and click properties.
•  Select the Security tab, then select radio buttons which activate the Edit buttons in Access Permissions group.
•  Add the account.
•  Reboot.

I look forward to receiving your test results.
0
 
Dhanasekaran SengodanCommented:
Remember that you are opening a document from a server process.  I don't know what you want to do because your code sample doesn't do anything with the document after opening and modifying it.

Remember that IIS runs under a different account and so may not have acces to the file system.

Remember that the Visual Studio web server runs in your local user context, so when it shells out to Word that's why you can see it.

Also remember that Word is a single-threaded application and is not suitable for use in a multi-threaded web server environment.  If you want to manipulate Word documents and send them back to the client in the browser I suggest that you buy a 3rd party component for your web server.  Look at http://www.aspose.com and look at their Words product as a start.
0
 
andre72Author Commented:
I'm sorry, I tried it out and gave NETWORK SERVICE all rights for access, activation and start but the error is still the same ...

Yes I reduce the code to only only line as I think anything else will already work if I can create a new instance if the class.
However it's no secret I need to convert Word documents to HTML, maybe two or three every day
I think for this simple task is no thrid party modul needed also the code for convertion is ready just not runable at the server ...
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
andre72Author Commented:
I've installed IIS 7 however I gave ASPNET also the ame right but also this doesn't solve the problem ...
0
 
andre72Author Commented:
Hundred tests later :-)
It seems that I can create a new instance when I include
<identity impersonate="true"/>

Open in new window

at web config

But now I get an error at this line:
Microsoft.Office.Interop.Word.Document oDoc = objApp.ActiveDocument;

Exception:
Command not available as no document is loaded

Any idea how to fix this?
<%@ Page Language="C#" Debug="true"%>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.Threading" %>

<script language="C#" runat="server">
    protected Microsoft.Office.Interop.Word.ApplicationClass objApp = new Microsoft.Office.Interop.Word.ApplicationClass();
    protected string strPathToUpload; //Path to upload files "Uploaded"
    protected string strPathToConvert; //Path to convert uploaded files and save
    object fltDocFormat = 10; //For filtered HTML Output
    protected object missing = System.Reflection.Missing.Value;
    protected object readOnly = false; //Open file in readOnly mode
    protected object isVisible = false;//The process has to be in invisible mode
        
void Page_Load(object sender, EventArgs e)
{
   string fName = "";

  Page.Response.Write("<html>");
  Page.Response.Write("<head>");
  Page.Response.Write("</head>");
  Page.Response.Write("<body>");
         object wName = @"C:\inetpub\wwwroot\target\testfile.doc";
         object hName = wName + ".html";
         if (File.Exists(hName.ToString())) File.Delete(hName.ToString());
         try
         {
         objApp.Documents.Open(ref wName,ref missing, ref readOnly, ref missing, ref missing, ref missing,ref missing, ref missing, ref missing, ref missing, ref missing,ref missing, ref missing, ref missing, ref missing, ref missing);
         Page.Response.Write("Geladen");
         }
         catch(Exception ex)
         {
         Page.Response.Write(ex.Message);
         }
         objApp.Visible = false;
         try
         {
         Microsoft.Office.Interop.Word.Document oDoc = objApp.ActiveDocument;
         Page.Response.Write("Active");
         }
         catch(Exception ex)
         {
         Page.Response.Write(ex.Message);
         }
         // oDoc.SaveAs(ref hName, ref fltDocFormat, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
         objApp.Quit(ref missing, ref missing, ref missing);
  Page.Response.Write("</body>");
  Page.Response.Write("</html>");
  Page.Response.End();
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body></body>
</html>

Open in new window

0
 
andre72Author Commented:
Well some steps more needed but now it works fine. Thanks for your support
0
 
UCTechsCommented:
Did you ever figure out a solution to this. I have hunted and hunted and can find nothing. I would be more than happy to post a new question if you have an answer as well.
0
 
andre72Author Commented:
Try DCOMConfg and set for DCM Word 97 - 2003 the tab Identy to "Interactive User". Also try this with C:\Windows\SysWOW64\comexp.msc .
If this doesn't solve the problem try <identity impersonate="true" userName="AnyAdmin" password="HisPassword" />

Qith this I make it work on every system ...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now