Using Word Interop Assembly

Discussion in 'ASP .Net' started by rwiegel@iastate.edu, Sep 20, 2007.

  1. Guest

    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
     
    , Sep 20, 2007
    #1
    1. Advertising

  2. Guest

    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
     
    , Sep 20, 2007
    #2
    1. Advertising

  3. <> wrote in message
    news:...

    > 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


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Sep 20, 2007
    #3
  4. Arnshea Guest

    On Sep 20, 5:11 pm, 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...
     
    Arnshea, Sep 20, 2007
    #4
  5. "Arnshea" <> wrote in message
    news:...

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


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Sep 20, 2007
    #5
  6. Guest

    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.
     
    , Sep 21, 2007
    #6
  7. <> wrote in message
    news:...

    > 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
     
    Mark Rae [MVP], Sep 21, 2007
    #7
  8. Guest

    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.
     
    , Sep 21, 2007
    #8
  9. <> wrote in message
    news:...

    > 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
     
    Mark Rae [MVP], Sep 21, 2007
    #9
  10. Nathan Guest

    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:...
    >
    >> 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
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
     
    Nathan, Sep 21, 2007
    #10
  11. Nathan Guest

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

    "Nathan" <> wrote in message
    news:%23ivM5NF$...
    > 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:...
    >>
    >>> 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
    >>
    >>
    >> --
    >> Mark Rae
    >> ASP.NET MVP
    >> http://www.markrae.net

    >
    >
     
    Nathan, Sep 21, 2007
    #11
  12. "Nathan" <> wrote in message
    news:%23ivM5NF$...

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


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Sep 21, 2007
    #12
  13. Arnshea Guest

    On Sep 20, 6:34 pm, "Mark Rae [MVP]" <> wrote:
    > "Arnshea" <> wrote in message
    >
    > news:...
    >
    > > 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/defaul.../support.microsoft.com/default.aspx/kb/288367
    >
    > Please do not advise anyone to do this...
    >
    > --
    > 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... :)
     
    Arnshea, Sep 21, 2007
    #13
  14. Guest

    Mark, thanks a lot. You were a big help.

    -Ryan
     
    , Sep 21, 2007
    #14
  15. Nathan Guest

    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



    <> wrote in message
    news:...
    > 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
    >
     
    Nathan, Sep 21, 2007
    #15
  16. Nick Guest

    "Mark Rae [MVP]" <> wrote in message
    news:emmnQD%23%...
    >
    > 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?
     
    Nick, Sep 21, 2007
    #16
  17. "Nick" <> wrote in message
    news:ed%231fZG$...

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


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Sep 21, 2007
    #17
  18. Nick Guest

    "Mark Rae [MVP]" <> wrote in message
    news:%23t$SE3G$...
    > "Nick" <> wrote in message
    > news:ed%231fZG$...
    >
    >> 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...
    >

    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.
     
    Nick, Sep 21, 2007
    #18
  19. "Nick" <> wrote in message
    news:O5DR4OH$...

    > "Mark Rae [MVP]" <> wrote in message
    > news:%23t$SE3G$...
    >> "Nick" <> wrote in message
    >> news:ed%231fZG$...
    >>
    >>> 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...
    >>

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


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Sep 21, 2007
    #19
  20. Nick Guest

    "Mark Rae [MVP]" <> wrote in message
    news:%23lXyDfH$...
    > "Nick" <> wrote in message
    > news:O5DR4OH$...
    >
    >> "Mark Rae [MVP]" <> wrote in message
    >> news:%23t$SE3G$...
    >>> "Nick" <> wrote in message
    >>> news:ed%231fZG$...
    >>>
    >>>> 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...
    >>>

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

    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.
     
    Nick, Sep 21, 2007
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luis Esteban Valencia
    Replies:
    2
    Views:
    2,986
    sanjupillai
    Sep 26, 2008
  2. Replies:
    1
    Views:
    787
    Bruce Barker
    Oct 10, 2005
  3. =?Utf-8?B?RHVzdGluIHZhbiBkZSBTYW5kZQ==?=

    ASP.NET 2.0 Word interop assembly

    =?Utf-8?B?RHVzdGluIHZhbiBkZSBTYW5kZQ==?=, Feb 22, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    30,256
    =?Utf-8?B?RHVzdGluIHZhbiBkZSBTYW5kZQ==?=
    Mar 16, 2006
  4. Richard Lewis Haggard
    Replies:
    0
    Views:
    436
    Richard Lewis Haggard
    Aug 4, 2006
  5. Nicola Garone

    How to strong name an assembly which use interop.shell32?

    Nicola Garone, Apr 15, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    369
    Nicola Garone
    Apr 19, 2004
Loading...

Share This Page