Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i run the application from Visual Studio, word document is opening, but the same code if i open from IIS( Same Machine ) word document is not opening showing this error message

"Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 8000401a.". 


Following is the code i am using to open and update the word document.

C#
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();

Microsoft.Office.Interop.Word.Document aDoc = null;

if (File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/CMS/Lease/temp.doc")))
{
    object readOnly = false;
    object isVisible = false;


    wordApp.Visible = false;

    aDoc = wordApp.Documents.Open(ref filename, ref missing, ref readOnly, ref missing, ref missing, ref missing,
        ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing,
        ref missing, ref missing, ref missing);

    aDoc.Activate();

    DataTable dtLease = BusinessLayer.CMS.Lease_Report(Convert.ToInt32(txtRec1.Text.Trim()), 1);
    if (dtLease.Rows.Count > 0)
    {
        DataRow dr = dtLease.Rows[0];
        string SupName = string.Empty;
        if (dr["First_name"] != DBNull.Value && dr["Surname"] != DBNull.Value)
        {
            this.FindAndReplace(wordApp, "<deptrep>", (string)dr["First_name"] + " " + (string)dr["Surname"]);
        }</deptrep>
Posted
Updated 6-Aug-13 21:32pm
v2

Microsoft discouraged the use of Office interop in server settings. Please see: http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2[^].

A better alternative would be using Open XML SDK. Please see my past answers:
Microsot office Interop[^],
Question Convert word to PDF without offce or openoffice[^],
How to add microsoft excel 15.0 object library from Add Reference in MS Visual Studio 2010[^].

See also this answer: Creating basic Excel workbook with Open XML[^].

Good luck,
-SA
 
Share this answer
 
Hi,

Save the Word file in some location and then open the word file through javascript using ActiveXObject from that location.

C#
function fnopen(str)
{
    var myapp = new ActiveXObject("Excel.Application")
    if(myapp != null)
    {
        myapp.visible = true;
        var filename = "filelocationstring;+ str + " ";
        myapp.workbooks.open(filename);
        this.window.close();
    }
    else
    {
        return false;
    }
}


Thanks
BS
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900