Real_coffee
asked on
Problem automating word on IIS
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.InteropServ ices.COMEx ception: Word could not fire the event.
Source Error:
Line 21: oWord = CreateObject("Word.Applica tion")
Line 22: oWord.Visible = True
Line 23: oDoc = oWord.Documents.Add("c:\te mp\standar d letter.dot")
Line 24:
Line 25:
Source File: C:\Inetpub\wwwroot\Beta\Wo rd Automation.aspx Line: 23
Stack Trace:
[COMException (0x800a1772): Word could not fire the event.]
Microsoft.Office.Interop.W ord.Docume nts.Add(Ob ject& Template, Object& NewTemplate, Object& DocumentType, Object& Visible) +0
ASP.word_automation_aspx.B utton1_Cli ck(Object sender, EventArgs e) in C:\Inetpub\wwwroot\Beta\Wo rd Automation.aspx:23
System.Web.UI.WebControls. Button.OnC lick(Event Args e) +111
System.Web.UI.WebControls. Button.Rai sePostBack Event(Stri ng eventArgument) +110
System.Web.UI.WebControls. Button.Sys tem.Web.UI .IPostBack EventHandl er.RaisePo stBackEven t(String eventArgument) +10
System.Web.UI.Page.RaisePo stBackEven t(IPostBac kEventHand ler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePo stBackEven t(NameValu eCollectio n postData) +36
System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +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?
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.InteropServ
Source Error:
Line 21: oWord = CreateObject("Word.Applica
Line 22: oWord.Visible = True
Line 23: oDoc = oWord.Documents.Add("c:\te
Line 24:
Line 25:
Source File: C:\Inetpub\wwwroot\Beta\Wo
Stack Trace:
[COMException (0x800a1772): Word could not fire the event.]
Microsoft.Office.Interop.W
ASP.word_automation_aspx.B
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.Page.RaisePo
System.Web.UI.Page.RaisePo
System.Web.UI.Page.Process
--------------------------
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>
*. Can u double check if the site is having Network Services permission propagated from the root and also check if the IUSR of the site has permission over the temp folder... of the server...
ASKER
PaulHews - you're saying the bottom-line / party-line is that we just don't do this? Ok, I take that onboard. Are there any 3rd party tools you would recommend that can get me round this 'mail merge' problem? one that can maybe do it in RTF format?
servoadmin - is that the c:\windows\temp folder?
Has anybody heard of these guys - http://www.mylittletools.net/en/mylittlewriter/
Think this would do what Im after?
servoadmin - is that the c:\windows\temp folder?
Has anybody heard of these guys - http://www.mylittletools.net/en/mylittlewriter/
Think this would do what Im after?
Yeah absltly... and for the tool u asked...there has been alot of discussions in experts exchange... select the best rated and appropriate..
https://www.experts-exchange.com/simpleSearch.jsp?q=mylittlewriter&searchSubmit=1&cid=315&redirectURL=%2F&gSearch=0
https://www.experts-exchange.com/simpleSearch.jsp?q=mylittlewriter&searchSubmit=1&cid=315&redirectURL=%2F&gSearch=0
ASKER
I have contacted mylittletools - their app will not open existing rtf files.
Just creates them on the fly which is good but not what I need.
Just creates them on the fly which is good but not what I need.
ASKER
Im checking out this solution - any feedback appreciated -
http://www.aspose.com/categories/file-format-components/aspose.words-for-.net-and-java/default.aspx
http://www.aspose.com/categories/file-format-components/aspose.words-for-.net-and-java/default.aspx
ASKER
servoadmin - permissions are good on c:\windows for IUSR. Word automation still fails
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Paul,
That's really elegant. Its creates a new RTF file, replacing the markers with data. Effectively it creates a new 'mail merged' letter (pity about the sweepstakes!).
line 11. process.start doesnt work for me - what are you trying to do there ? VS tells me that process is not declared?
Ive spent all day working at this from another/wrong angle; using streamwriter to create a csv that a word template is merged with. My idea was just to display a link to the .dot file that the user could click to 'launch' Word themselves. What do you think?
That's really elegant. Its creates a new RTF file, replacing the markers with data. Effectively it creates a new 'mail merged' letter (pity about the sweepstakes!).
line 11. process.start doesnt work for me - what are you trying to do there ? VS tells me that process is not declared?
Ive spent all day working at this from another/wrong angle; using streamwriter to create a csv that a word template is merged with. My idea was just to display a link to the .dot file that the user could click to 'launch' Word themselves. What do you think?
>line 11. process.start doesnt work for me - what are you trying to do there ? VS tells me that process is not declared?<
That just launches the default RTF editor to show the newly created file... It's not desirable in an ASP.NET application. (Process is in the System.Diagnostics namespace.)
>using streamwriter to create a csv that a word template is merged with. My idea was just to display a link to the .dot file that the user could click to 'launch' Word themselves. What do you think?
I could see some problems with the merge data source not being available on the client PC, and possibly the Word template opening in read-only mode.
That just launches the default RTF editor to show the newly created file... It's not desirable in an ASP.NET application. (Process is in the System.Diagnostics namespace.)
>using streamwriter to create a csv that a word template is merged with. My idea was just to display a link to the .dot file that the user could click to 'launch' Word themselves. What do you think?
I could see some problems with the merge data source not being available on the client PC, and possibly the Word template opening in read-only mode.
ASKER
Completely agree with you regarding streamwriter and the merged word doc.
Your solution with the RTF file was exactly what I needed.
Your solution with the RTF file was exactly what I needed.
ASKER
In my opinion this was the absolute correct approach to Word automation in ASP.NET (Dont - use RTF files instead).
Considerations for server-side Automation of Office
http://support.microsoft.com/?kbid=257757