Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Using Word Interop Assembly

Reply
Thread Tools

Using Word Interop Assembly

 
 
rwiegel@iastate.edu
Guest
Posts: n/a
 
      09-20-2007
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

 
Reply With Quote
 
 
 
 
rwiegel@iastate.edu
Guest
Posts: n/a
 
      09-20-2007
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

 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      09-20-2007
<> wrote in message
news: oups.com...

> 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...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/Aspos...s/Default.aspx


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
Arnshea
Guest
Posts: n/a
 
      09-20-2007
On Sep 20, 5:11 pm, rwie...@iastate.edu wrote:
> 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...

 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      09-20-2007
"Arnshea" <> wrote in message
news: ps.com...

> 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...US;q257757#kb2
http://support.microsoft.com/default.aspx/kb/288367

Please do not advise anyone to do this...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
rwiegel@iastate.edu
Guest
Posts: n/a
 
      09-20-2007
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.

 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      09-20-2007
<> wrote in message
news: ups.com...

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


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
rwiegel@iastate.edu
Guest
Posts: n/a
 
      09-21-2007
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.

 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      09-21-2007
<> wrote in message
news: oups.com...

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


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
Nathan
Guest
Posts: n/a
 
      09-21-2007
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

"Mark Rae [MVP]" <> wrote in message
news:%23v7zC78%...
> <> wrote in message
> news: oups.com...
>
>> 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...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/Aspos...s/Default.aspx
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deployment of a WebApp that uses Word 10.0 via Interop.Word.dll object - How do I register the COM?? Luis Esteban Valencia ASP .Net 2 09-26-2008 08:26 PM
Problem passing multi-demsioned array from conventional ASP/Javascript to a C# interop assembly Richard Lewis Haggard ASP .Net 0 08-04-2006 12:02 AM
ASP.NET 2.0 Word interop assembly =?Utf-8?B?RHVzdGluIHZhbiBkZSBTYW5kZQ==?= ASP .Net 3 03-16-2006 12:11 PM
Deployment of Microsoft Office Xp Primary Interop Assembly kunallalwani@gmail.com ASP .Net 1 10-10-2005 04:34 PM
How to strong name an assembly which use interop.shell32? Nicola Garone ASP .Net Building Controls 1 04-19-2004 02:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57