Access denied to Office from ASP.Net application using microsoft.interope.word


I am working for an ERP system and we send documents to our office employees to sign the document digitally, for that purpose we want to read .docx file, and using Microsoft.Office.Interop.Word reference.

following is the code I have tried:

            string allText = "";
            // if word file
            if (fileExtension == ".docx" || fileExtension == ".doc")
                Stopwatch stopwatch = new Stopwatch();
                Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
                object miss = System.Reflection.Missing.Value;
                object readOnly = true;
                object Path = filePath;
                // getting the document
                Microsoft.Office.Interop.Word.Document doc = word.Documents.Open(ref Path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);

                // if document contains at least single line of signature
                bool docHasSignature = doc.Content.Find.Execute("{{signature_");
                if (docHasSignature)
                    // reading all the and appending in the string
                    allText += (doc.Content.Text.ToString());

                //signatureCount = 3;

when I try to run this code from the user side and request for this method it give following error:

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

I have also tried the step provided on this link but still same result appears, it will be very thankful act if someone guide me.


1 Answer


Use the Open XML SDK instead.

The Considerations for server-side Automation of Office page states the following:

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.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

The article describes possible alternatives to using Office automation.

answered on Stack Overflow May 18, 2020 by Eugene Astafiev • edited Jun 20, 2020 by Community

User contributions licensed under CC BY-SA 3.0