Searching a word in a document in C# is errors

0

I wrote the code for: searching a word in a document that works without problems in the Console Application, but does not work in ASP.NET Application when I click the button:

using Microsoft.Office.Interop.Word;

 Application objWordApp = new Application();
                objWordApp.Visible = false;
                object missing = System.Reflection.Missing.Value;
                Document objDoc;
                objDoc = objWordApp.Documents.Open(fileURL, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing,
                ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                                ref missing, ref missing);

                object findText = "Tags";

                objDoc.Content.Find.ClearFormatting();
                try
                {
                    if (objDoc.Content.Find.Execute(ref findText,
                    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing))
                    {
                        Console.WriteLine("Text found: Name document - " + "'" + docTitle + "'");
                    }
                    objDoc.Close(ref missing, ref missing, ref missing);
                    objWordApp.Application.Quit(ref missing, ref missing, ref missing);
                }
                catch (Exception ex)
                {
                    objDoc.Close(ref missing, ref missing, ref missing);
                    objWordApp.Application.Quit(ref missing, ref missing, ref missing);
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                test11.Text = ex.ToString();
            }

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

I looked at a lot of information on the forums, did everything as written in the article, nothing helps, the error was not eliminated.

1.DCOM Error : Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005.

2.Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046}

c#
asked on Stack Overflow Feb 7, 2019 by Fox

1 Answer

1

Can you try this One

Step1:

Ref this link : Interop.Word Documents.Open is null

If you are still looking for the answer I have found it just a moment ago for my project.

Open DCOM Config Settings:

  1. Start -> dcomcnfg.exe

  2. Computer

  3. Local Computer

  4. Config DCOM

  5. Search for Microsoft Word 97-2003 Documents -> Properties Tab Identity, change from Launching User to Interactive User

Step2:

Go to your Project do the below change..

enter image description here

Step3:

Go to the IIS Server, Add the Application Pool like a below Configuration and Map into to your site or application.

enter image description here


User contributions licensed under CC BY-SA 3.0