Hi All,
I have created an ASP.NET project and for one of the pages I want to
pop open a word template and fill in some info. In Visual Studio
2005, I added the COM reference Microsoft Office 11.0 Object library.
This adds a few dll's to the \bin directory. When I run the code from
visual studio, it works fine. When I copy it to the server (dll's and
all), I get the following error when I navigate to the page:
Retrieving the COM class factory for component with CLSID
{00020906-0000-0000-C000-000000000046} failed due to the following
error: 80080005
Any ideas? I'm sure it has to do with how I added the assembly, but I
have very limited experience in this area. I have done similar
projects using windows forms and you can use 'Copy Local' to move the
assembly reference into the working directory. How can I do something
similar with ASP.NET?
Thanks,
Ryan
rwiegel@iastate.edu - 20 Sep 2007 22:17 GMT
Here is the code I am using:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Runtime.InteropServices;
using System.Drawing;
using Microsoft.Office.Interop.Word;
using System.ComponentModel;
using System.Windows.Forms;
public partial class WordTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
object missing = Type.Missing;
Microsoft.Office.Interop.Word.ApplicationClass oWordApp =
new Microsoft.Office.Interop.Word.ApplicationClass();
oWordApp.Visible = true;
Microsoft.Office.Interop.Word.Document oWordDoc = new
Microsoft.Office.Interop.Word.Document();
object oTemplate = "C:\\BOL.dot";
oWordDoc = oWordApp.Documents.Add(ref oTemplate, ref
missing, ref missing, ref missing);
oWordDoc.Activate();
object oBookMark = "shipperBOL";
oWordDoc.Bookmarks.get_Item(ref oBookMark).Range.Text =
"Some Text Here";
}
catch (Exception exc)
{
errorLabel.Text += exc.Message;
}
}
}
-Ryan
Mark Rae [MVP] - 20 Sep 2007 22:39 GMT
> Retrieving the COM class factory for component with CLSID
> {00020906-0000-0000-C000-000000000046} failed due to the following
> error: 80080005
>
> Any ideas? I'm sure it has to do with how I added the assembly
Nope - it has nothing to do with that... It's simply that server-side Office
automation doesn't work because Office just wasn't designed to run in that
environment - Microsoft won't support any solution which even tries to use
it:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2
See the "MORE INFORMATION" section, particularly the bold paragraph...
If you need to manipulate Word documents server-side, you need this:
http://www.aspose.com/Products/Aspose.Words/Default.aspx

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Nathan - 21 Sep 2007 14:29 GMT
Hey Mark,
This is kind of a random suggestion, but since the Office Interop works
better in a Windows environment, you might try setting up a Windows Service
that watches a database table for information about "jobs" to pickup. Make
it synchronous (only one job at a time because running Word COM is just like
using it manually; you can only edit one document at a time per Word
application). Let the service pickup jobs and generate the word docs for you
with the information submitted from the website. You can tag the job records
with some kind of status so you can see the status on the website. Then when
it's done, make the end result word doc available to the site via its
status.
Just an idea. You also might check out using a third party utility like
Aspose (aspose.com) or TXTextControl Server (textcontrol.com) which will
give you an API to manipulate word docs without using Office COM to do it.
Then you could do it directly in the site or in a windows service easily.
But it comes with a cost.
Good luck!
-Nathan
>> Retrieving the COM class factory for component with CLSID
>> {00020906-0000-0000-C000-000000000046} failed due to the following
[quoted text clipped - 12 lines]
> If you need to manipulate Word documents server-side, you need this:
> http://www.aspose.com/Products/Aspose.Words/Default.aspx
Nathan - 21 Sep 2007 14:41 GMT
Sorry Mark, This post was for Ryan. I misread.
> Hey Mark,
>
[quoted text clipped - 34 lines]
>> If you need to manipulate Word documents server-side, you need this:
>> http://www.aspose.com/Products/Aspose.Words/Default.aspx
Mark Rae [MVP] - 21 Sep 2007 14:43 GMT
Nathan,
> This is kind of a random suggestion
I think you're replying to the wrong post...
> You also might check out using a third party utility like Aspose
Yes indeed - check out my posts in the rest of this thread (and countless
others) on the use server-side Office automation...

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Arnshea - 20 Sep 2007 23:24 GMT
> Hi All,
>
[quoted text clipped - 18 lines]
>
> Ryan
The COM object (in this case, Word) needs to be installed on the
server. You can do this by installing Word/Office on the server.
This will work but I think they're encouraging people to use the
PIAs...
Mark Rae [MVP] - 20 Sep 2007 23:34 GMT
> The COM object (in this case, Word) needs to be installed on the
> server. You can do this by installing Word/Office on the server.
Do NOT do this under any circumstances...
> This will work
No it won't! Office was not designed to operate in this way:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2
http://support.microsoft.com/default.aspx/kb/288367
Please do not advise anyone to do this...

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
rwiegel@iastate.edu - 21 Sep 2007 00:25 GMT
Well, since office is already on the server and it still doesn't work,
I think the message is pretty clear. I will take Mark's suggestion
and not do it that way.
Thank you both for your replies.
Does anybody know of anything any cheaper than Aprose? $900 for one
customer site seems awfully steep. And I don't have enough customers
requesting this to amke it worth buying the OEM.
Mark Rae [MVP] - 21 Sep 2007 00:48 GMT
> Does anybody know of anything any cheaper than Aprose?
No.
What are your actual requirements for this? There are probably other ways of
doing things...

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
rwiegel@iastate.edu - 21 Sep 2007 01:01 GMT
The user is requesting a shipment from this company. The Word doc (or
PDF) is basically going to be a receipt with the information from the
shipment request. So, the receipt is a template that will get some
blanks filled in.
Mark Rae [MVP] - 21 Sep 2007 08:27 GMT
> The user is requesting a shipment from this company. The Word doc (or
> PDF) is basically going to be a receipt with the information from the
> shipment request. So, the receipt is a template that will get some
> blanks filled in.
Oh right - no need at all to use Word for that...
You could create an HTML document and then save it with a .doc extension -
Word will treat it like a normal document.
Alternative, making a PDF in .NET is very simple - I use this:
http://www.siberix.com/
There is also an open source library, I believe...

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
rwiegel@iastate.edu - 21 Sep 2007 15:06 GMT
Mark, thanks a lot. You were a big help.
-Ryan
Nick - 21 Sep 2007 16:45 GMT
> What are your actual requirements for this? There are probably other ways
> of doing things...
I need to replace a DCOM application running on Windows 2003. It is using
Word for mailmerge with SQL data to create a file for the client
application. How to do this better?
Mark Rae [MVP] - 21 Sep 2007 17:37 GMT
> I need to replace a DCOM application running on Windows 2003. It is using
> Word for mailmerge with SQL data to create a file for the client
> application. How to do this better?
Word can use a variety of file formats for mailmerge - doesn't have to be a
Word document...
Choose something like CSV...

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Nick - 21 Sep 2007 18:20 GMT
>> I need to replace a DCOM application running on Windows 2003. It is using
>> Word for mailmerge with SQL data to create a file for the client
[quoted text clipped - 4 lines]
>
> Choose something like CSV...
Perhaps I am not making it clear. The file produced from my mailmerge
contain form letters. MS Word is used to combine a letter template with SQL
data to create a printer file.
Mark Rae [MVP] - 21 Sep 2007 18:49 GMT
>>> I need to replace a DCOM application running on Windows 2003. It is
>>> using Word for mailmerge with SQL data to create a file for the client
[quoted text clipped - 8 lines]
> contain form letters. MS Word is used to combine a letter template with
> SQL data to create a printer file.
Is it, then, actually necessary to use Word at all? Are the printed letters
alone the goal here, or do you need a Word document so that users can edit
it before eventually printing it...?

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Nick - 21 Sep 2007 20:13 GMT
>>>> I need to replace a DCOM application running on Windows 2003. It is
>>>> using Word for mailmerge with SQL data to create a file for the client
[quoted text clipped - 12 lines]
> letters alone the goal here, or do you need a Word document so that users
> can edit it before eventually printing it...?
Thank you. I appreciate your time on this.
The letters are finalized and approved before printing but I just want to
concentrate on replacing the mailmerge of SQL data with the templates. The
tool must allow endusers to create and make changes to the form letter
templates.
Mark Rae [MVP] - 21 Sep 2007 21:06 GMT
> The letters are finalized and approved before printing but I just want to
> concentrate on replacing the mailmerge of SQL data with the templates. The
> tool must allow endusers to create and make changes to the form letter
> templates.
Whoa...!
We've now moved quite a distance away from getting ASP.NET to churn out a
Word document from a mailmerge operation - now you're saying that you need
the users to be able to create and/or amend the mailmerge templates - in a
browser...???
If that is really what you mean...?

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Nick - 24 Sep 2007 12:56 GMT
>> The letters are finalized and approved before printing but I just want to
>> concentrate on replacing the mailmerge of SQL data with the templates.
[quoted text clipped - 9 lines]
>
> If that is really what you mean...?
MS Word is used create and/or amend the mailmerge templates.
ASP.NET will be used to provide a user interface to select SQL Data combine
it with the mailmerge templates and send create a Word document of form
letters. The old application is VB form application on WinXP connected to a
DCOM application running on Windows 2003.
Mark Rae [MVP] - 24 Sep 2007 13:43 GMT
> MS Word is used create and/or amend the mailmerge templates.
That makes things a whole lot easier...
> ASP.NET will be used to provide a user interface to select SQL Data
> combine it with the mailmerge templates and send create a Word document of
> form letters.
No problem, then...
1) The user selects the data - ASP.NET either populates a DataSet in memory,
or writes out a temporary CSV file.
2) The user selects the template to use from a DropDownList populated with
the GetFiles method of the Directory object in System.IO
3) ASP.NET uses Aspose to create a new Word document via mailmerge using the
data selected above
4) You save this document somewhere and provide a hyperlink for the users to
click and download it, or you stream it down to them so that it loads in
their browser - not recommended if the document is large...
5) The user checks the document, makes changes as requred, and then prints
it.
> The old application is VB form application on WinXP connected to a DCOM
> application running on Windows 2003.
I'm sure it did - but ASP.NET can't...

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Nick - 24 Sep 2007 16:25 GMT
>> MS Word is used create and/or amend the mailmerge templates.
>
[quoted text clipped - 26 lines]
>
> I'm sure it did - but ASP.NET can't...
I get it. Aspose.Words for .NET is recommended over MS Word Automation on
Windows 2003. Let me check out the trial version first.
Thank you for your help.
Arnshea - 21 Sep 2007 14:45 GMT
> > The COM object (in this case, Word) needs to be installed on the
> > server. You can do this by installing Word/Office on the server.
[quoted text clipped - 10 lines]
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net
Doh! Thanks. I hadn't actually tried but now know not to if a
similar need arises... :)
Nathan - 21 Sep 2007 15:34 GMT
I'm showing off my noob newsgroup skills. I just posted reply to the wrong
thread. This one is for Ryan.
This is kind of a random suggestion, but since the Office Interop works
better in a Windows environment, you might try setting up a Windows Service
that watches a database table for information about "jobs" to pickup. Make
it synchronous (only one job at a time because running Word COM is just like
using it manually; you can only edit one document at a time per Word
application). Let the service pickup jobs and generate the word docs for you
with the information submitted from the website. You can tag the job records
with some kind of status so you can see the status on the website. Then when
it's done, make the end result word doc available to the site via its
status.
Just an idea. You also might check out using a third party utility like
Aspose (aspose.com) or TXTextControl Server (textcontrol.com) which will
give you an API to manipulate word docs without using Office COM to do it.
Then you could do it directly in the site or in a windows service easily.
But it comes with a cost.
Good luck!
-Nathan
> Hi All,
>
[quoted text clipped - 18 lines]
>
> Ryan