问题描述
我知道这可能是一个重复的问题,但是我尝试了前面讨论的几乎所有步骤,但是没有运气。我也尝试了与我的情况类似的链接,并完成了所有说明,但仍然无法解决错误:Retrieving the COM class factory for component with CLSID failed due to the following error: 80070005 Access is denied
在我的asp.net Web应用程序中,我需要打开Microsoft Word文件,我可以使用本地计算机中的程序集引用“ Microsoft.Office.Interop.Word”来执行此操作。但是,当我在服务器(Windows Server 2012 r2)上运行它时,我会遇到上述错误。我还在本地计算机上使用的服务器中安装了相同版本的MS Office。
下面是代码:
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 isVisible,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;
}