I know it might be a duplicate question but I tried almost all the steps that were discussed earlier, but no luck. I have also tried this link which is similar to my case and completed all the instruction, but again failed to resolve the error : Retrieving the COM class factory for component with CLSID failed due to the following error: 80070005 Access is denied
In my asp.net web application, I have a requiremnt of opening Microsoft Word file, which I am able to do it using assembly reference 'Microsoft.Office.Interop.Word' in my local machine. But when I am running it on the server (Windows server 2012 r2), then I face the error mentioned. I have also installed the same version of MS Office in the server which I am using in the local machine.
Below is the code behind:
protected void Button1_Click(object sender, EventArgs e)
{
fileupload1.SaveAs(Server.MapPath("~/ControlPanel/DocumentCache/" + fileupload1.FileName));
object filename = Server.MapPath("~/ControlPanel/DocumentCache/" + fileupload1.FileName);
Microsoft.Office.Interop.Word.ApplicationClass AC = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
try
{
doc = AC.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 isVisible, ref missing, ref missing, ref missing);
txt_DContent.Text = doc.Content.Text;
}
catch (Exception ex)
{
lblMessage.Text = ex.ToString();
}
INSERTDATAT(); // Method to insert the record
// AC.Quit(); This is to quit MS word that was opened to read the ms word file in textbox txt_DContent
((_Application)AC.Application).Quit(false);
Session["MyFile"] = fileupload1.FileName;
}
I have fixed the error with the following 2 steps:
Adding <identity impersonate="true" />
inside <system.web> in web.config file
I have created a Security Logins in my Database for the NT AUTHORITY\IUSR and gave all the required permission, display below:
User contributions licensed under CC BY-SA 3.0