none
Updating word document from ASP.Net page RRS feed

  • Question

  • I am trying to update word doucment using bookmark from an ASP.Net page.

    Development environment has Windows 7 64, Office 2010, Office runtime

    using Microsoft.Office.Interop.Word;

                   

    try
                {
                    Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
                    Document wordDoc = new Document();

                    object fileName = "E:\\Employee.docx";
                    object readOnly = false;
                    object isVisible = true;
                    object oMissing = System.Reflection.Missing.Value;

                    wordApp.Documents.Open(fileName, ref oMissing, readOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, isVisible, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                    wordDoc.Activate();

                    if (wordDoc.Bookmarks.Exists("EmployeeName"))
                    {
                        object oBookmark = "EmployeeName";
                        wordDoc.Bookmarks.get_Item(ref oBookmark).Range.Text = "me";
                    }


                    wordApp.Documents.Save(ref oMissing, ref oMissing);
                    wordApp.Application.Quit(ref oMissing, ref oMissing, ref oMissing);
                }
                catch (Exception expn)
                {
                    Response.Write("<br>" + expn.Message);
                }

    I am getting error message:

    Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

    Created folder C:\Windows\SysWOW64\config\systemprofile\Desktop also in System32/config/systemprofile/Desktop and assigned Network Services with appropriate rights

    Then, did:

    In DCOMCNFG, right click on the My Computer and select properties. 
    2. Choose the COM Securities tab
    3. In Access Permissions, click "Edit Defaults" and add Network Service to it and give it "Allow local access" permission. Do the same for <Machine_name>\Users.
    4. In launch and Activation Permissions, click "Edit Defaults" and add Network Service to it and give it "Local launch" and "Local Activation" permission.

    Still having the same issue, any workaround will be appreciated.

    Thursday, November 6, 2014 7:51 AM

Answers

  • Hi Raj Krish,

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    I suggest that you use alternatives to server-side Automation, more detail you can refer to link below:
    Considerations for server-side Automation of Office

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 7, 2014 7:11 AM
    Moderator