?
Solved

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

Posted on 2010-11-25
8
Medium Priority
?
877 Views
Last Modified: 2012-05-10
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
Comment
Question by:andre72
  • 5
  • 2
8 Comments
 
LVL 14

Accepted Solution

by:
Dhanasekaran Sengodan earned 2000 total points
ID: 34215807
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
 
LVL 14

Expert Comment

by:Dhanasekaran Sengodan
ID: 34215813
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
 

Author Comment

by:andre72
ID: 34219135
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
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 

Author Comment

by:andre72
ID: 34219260
I've installed IIS 7 however I gave ASPNET also the ame right but also this doesn't solve the problem ...
0
 

Author Comment

by:andre72
ID: 34219940
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
 

Author Closing Comment

by:andre72
ID: 34230214
Well some steps more needed but now it works fine. Thanks for your support
0
 

Expert Comment

by:UCTechs
ID: 34449734
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
 

Author Comment

by:andre72
ID: 34451420
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question