Cannot open Word document after publishing (Office.Interop.Word)

I cannot open Word document in c# after publishing to IIS

It can open Word document and replace any text in debug mode by using Microsoft.Interop.Office.Word. When I publish the project, it return the following error:

object reference not set to an instance of an object

Here is my code:

try {

Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application { Visible = true };

Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref fileName, ReadOnly: false, Visible: true);

doc.Activate();

...

}

The file path is correct. I found that the doc object returns null value.

Working environment:

  • Windows Server 2012
  • Visual Studio Professional 2012
  • .Net framework 3.5
  • Microsoft Office 2007
  • I try to add IUSR account and set enough permission to the folder which contains Word documents. It stills return the same error message. But it can work properly in debug mode...

    Thanks for your help

    链接地址: http://www.djcxy.com/p/55926.html

    上一篇: Word Documents.Count在MS Access 2016中不正确

    下一篇: 发布后无法打开Word文档(Office.Interop.Word)