【发布时间】:2020-09-15 16:31:26
【问题描述】:
我知道这可能是一个重复的问题,但我几乎尝试了前面讨论的所有步骤,但没有运气。我也尝试过这个与我的案例类似的链接并完成了所有指令,但再次未能解决错误: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 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;
}
【问题讨论】:
-
我尝试了您提到的链接中的步骤,但无法解决。无论如何,谢谢。
标签: c# ms-word office-interop