[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2010-11-25
8
Medium Priority
?
823 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …
Suggested Courses

649 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