Using Word Interop Assembly

R

rwiegel

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
 
R

rwiegel

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
 
M

Mark Rae [MVP]

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
 
A

Arnshea

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

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...
 
R

rwiegel

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.
 
M

Mark Rae [MVP]

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...
 
R

rwiegel

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.
 
M

Mark Rae [MVP]

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...
 
N

Nathan

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
 
N

Nathan

Sorry Mark, This post was for Ryan. I misread.

Nathan said:
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



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
 
M

Mark Rae [MVP]

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...
 
N

Nathan

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
 
N

Nick

Mark Rae said:
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?
 
M

Mark Rae [MVP]

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...
 
N

Nick

Mark Rae said:
Word can use a variety of file formats for mailmerge - doesn't have to be
a Word document...

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.
 
M

Mark Rae [MVP]

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.


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...?
 
N

Nick

Mark Rae said:
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...?
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top