Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法打开C#Word文档_C#_Asp.net_Iis 7_Iis 6_Ms Word - Fatal编程技术网

无法打开C#Word文档

无法打开C#Word文档,c#,asp.net,iis-7,iis-6,ms-word,C#,Asp.net,Iis 7,Iis 6,Ms Word,我有一个网站,可以在用户浏览器上打开Word文档,并在文档中填写特定值: protected void Page_Load(object sender, EventArgs e) { string source = "c:\TemplateDocument.doc"; string destination = "c:\Temp.doc"; File.Copy(source, destination, true); Microsoft.Office.I

我有一个网站,可以在用户浏览器上打开Word文档,并在文档中填写特定值:

 protected void Page_Load(object sender, EventArgs e)
 {
     string source = "c:\TemplateDocument.doc";
     string destination = "c:\Temp.doc";
      File.Copy(source, destination, true);
     Microsoft.Office.Interop.Word._Application oWord;
     Microsoft.Office.Interop.Word._Document oDoc;
     oWord = new Microsoft.Office.Interop.Word.Application();
     oDoc = oWord.Document.Open(destination, ReadOnly: false, Visible: false);
     oDoc.Tables[1].Rows[1].Cells[1].Range.Text = "Hello world"; // Simplified for the example
     oDoc.SaveAs2(destination);
     oDoc.Close();
     Response.Clear();
     Response.ContentType = "application/msword";
     Response.AddHeader("Content-Disposition", "inline;TemplateDocument.doc");
     Response.WriteFile(destination);
     Response.End();
     File.Delete(destination);

  }
上面的代码在我们的旧服务器IIS6上运行得非常好

但是,我们将服务器升级到IIS7,并使其与DFS一起工作

(DFS—基本上是两台复制服务器)

现在发生的情况是,
oDoc
即使在执行了
Open()
命令后仍然保持为空

当我尝试访问
oDoc
中的任何内容时(例如
oDoc.Tables
),我会得到一个
NullReferenceException

当在服务器上本地运行代码时,它会工作;一旦发布,我就得到了例外

还有什么可能是相关的?代码指的是Office 2010的dll,它是安装在服务器上的Office(升级之前也是如此,所以我不认为这是导致问题的原因)


提前谢谢

也许你的IIS需要以32位运行?IIS进程是否有权访问office DLL?您的IIS是以非用户身份运行,还是使用forms auth或windows auth?windows授权。您认为问题在于访问DLL吗?因为代码可以创建
\u应用程序
\u文档
的实例,但不能加载实际文档。请检查它是否有帮助?否则,您的IIS可能需要以32位运行?IIS进程是否有权访问office DLL?您的IIS是以非用户身份运行,还是使用forms auth或windows auth?windows授权。您认为问题在于访问DLL吗?因为代码可以创建
\u应用程序
\u文档
的实例,但不能加载实际文档。请检查它是否有帮助?如果不行的话