使用相对路径
Server.MapPath

解决方案 »

  1.   

    Object reference not set to an instance of an object,这是告诉你为将对象引用设置到对象的实例,也就是说你用的对象没有初始化。其实是告诉你服务器上还没有安装 Office。
      

  2.   

    当然,路径问题也要改一下,用 Server.MapPath() 方法。
      

  3.   

    难道在声明的时候必须要设为null吗?我装office了啊
      

  4.   

    是 oTemplateWord = new Word.Application(); 出错吗?
      

  5.   

    如果加了try语句直接就跳到catch了我觉得是oTemplateDoc = oTemplateWord.Documents.Open(ref templateFileName,
      ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
      ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
      ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
      }不能正确打开word。所以下面无法执行。如果不加try
    就显示int paraCount = oTemplateDoc.Paragraphs.Count。错误
      

  6.   

    你的 oTemplateDoc 在哪里被实例化的?
      

  7.   

    这个没法测试啊。我用try直接就跳到catch了。并且本地运行还没错。无法测试哪个地方错了啊
      

  8.   

    知道了,将你的文件路径修改一下吧。应该是路径错误造成的错误。用 Server.MapPath()。
      

  9.   

    oTemplateDoc = oTemplateWord.Documents.Open(ref templateFileName,
      ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
      ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
      ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);这一句将oTemplateDoc 实例化。但是这句却不能执行
      

  10.   

    oTemplateDoc = oTemplateWord.Documents.Open(),这是接受 open 方法的返回值,如果你的路径不对,返回值就是空的,所以后续逻辑出了空引用的问题。
      

  11.   

    比如说,如果将模板文件存放在网站根目录下 upload 文件夹中,那么你该将上述 C:\xxxx 改为:Server.MapPath("~/upload/template.doc")。