Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Problem automating word on IIS

Avatar of Real_coffee
Real_coffee asked on
Microsoft IIS Web ServerASP.NETVisual Basic.NET
12 Comments1 Solution2772 ViewsLast Modified:
Hi experts,

Scenario / Goal

I am writing an Intranet system that uses data on an sql server. The web application needs to be able to 'mail merge' MS Word templates with some basic client details.

I am using Visual Studio 2008 and within that environment the application works fine; It launches Word and can do the merge. When I try to deploy to my Internal webserver the app crashes with the following output:
*****

Server Error in '/Beta' Application.
--------------------------------------------------------------------------------

Word could not fire the event.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Word could not fire the event.

Source Error:


Line 21:         oWord = CreateObject("Word.Application")
Line 22:         oWord.Visible = True
Line 23:         oDoc = oWord.Documents.Add("c:\temp\standard letter.dot")
Line 24:        
Line 25:        
 

Source File: C:\Inetpub\wwwroot\Beta\Word Automation.aspx    Line: 23

Stack Trace:


[COMException (0x800a1772): Word could not fire the event.]
   Microsoft.Office.Interop.Word.Documents.Add(Object& Template, Object& NewTemplate, Object& DocumentType, Object& Visible) +0
   ASP.word_automation_aspx.Button1_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\Beta\Word Automation.aspx:23
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

 --------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
*****

Environment / History

I am using an XP Pro (SP2) machine as the webserver
Running IIS 5.1
I have word 2003 installed on the server
I have installed the MS Office 2003 interop on the server
My test aspx page is attached. It displays the current user and that user is displaying as ASPNET when I run it on the server.

On the server I have done the following to try to resolve the situation -

DCOMCNFG.exe / Found the component (Microsoft Word Document)
Properties / security tab / added ASPNET user to customise settings in launch/access/config
Identity tab is set to 'The launching user'
This changed an initial error message of 'Exception Details: System.Exception: Cannot create ActiveX component.' to the following error where it cannot fire the event.

Any thoughts?



<%@ Page Language="VB" %>
 
<%@ Import Namespace = "System.Runtime.InteropServices"%>
<%@ Import Namespace = "Microsoft.Office.Interop.Word"%>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<script runat="server">
 
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim oWord As Microsoft.Office.Interop.Word.Application 'Word.Application
        Dim oDoc As Microsoft.Office.Interop.Word.Document 'Word.Document
       
        'Launch Word
        oWord = CreateObject("Word.Application")
        oWord.Visible = True
        
        'Start a new doc based upon a template
        oDoc = oWord.Documents.Add("c:\temp\standard letter.dot")
        
        
        'Lets insert some values in the documents bookmarks
        oDoc.Bookmarks.Item("contact").Range.Text = "Mr A S Pnet"
        oDoc.Bookmarks.Item("addr1").Range.Text = "Cobweb Cottage"
        oDoc.Bookmarks.Item("addr2").Range.Text = "1 High Street"
        oDoc.Bookmarks.Item("addr3").Range.Text = "Bunbury"
        oDoc.Bookmarks.Item("addr4").Range.Text = "Cheshire"
        oDoc.Bookmarks.Item("postcode").Range.Text = "CH 1AB"
        oDoc.Bookmarks.Item("greeting").Range.Text = "Mr Pnet"
                
        'Close everything down
        oWord = Nothing
        oDoc = Nothing
               
    End Sub
</script>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Automation for the nation!</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
        <br />
    <%=Environment.UserName%>
    </div>
    </form>
</body>
</html>
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHewsFlag of Canada image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 12 Comments.
See Answers