当前位置:编程学习 > C#/ASP.NET >>

Word 在试图打开文件时遇到错误

为什么我在网站中调试的时候出现错误
在浏览器中显示的是Word 在试图打开文件时遇到错误。
请尝试下列方法:
* 检查文档或驱动器的文件权限。
* 确保有足够的内存和磁盘空间。
* 用文本恢复转换器打开文件。 (F:\周老师\毕业设计\QE_WebSites\UpLoad\)
在代码中显示的错误如下图


代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using USTC;
using Word = Microsoft.Office.Interop.Word;
using System.Data.SqlClient;
using System.Data;
using System.Diagnostics;


public partial class Inform_QE_Word : System.Web.UI.Page
{
    DbManager db = new DbManager();
    public string countyName = string.Empty; //乡镇名称  
    public string documentFullName = string.Empty; //预案全称(包括后缀名)  
    public string documentName1 = string.Empty; //预案名称  
    protected void Page_Load(object sender, EventArgs e)
    {
        //GetData();
        //GetGoodsInfo();
        if (!IsPostBack)
        {
            try
            {
                //根据传递过来的乡镇名称获取到文件名称  
                countyName = Server.UrlDecode(Request.QueryString["id"].ToString().Trim());
                DM dm = new DM();
                string strSQL = "select documentName from QE_Inform";
                documentFullName = dm.getsql(strSQL).Tables[0].Rows[0]["documentName"].ToString().Trim();
                documentName1 = documentFullName.Substring(0, documentFullName.LastIndexOf('.'));
            }
            catch (Exception)
            {
                documentFullName = "";
            }
        }
        // 在此处放置用户代码以初始化页面   
        Word.ApplicationClass word = new Word.ApplicationClass();
        Type wordType = word.GetType();
        Word.Documents docs = word.Documents; // 打开文件   
        Type docsType = docs.GetType();
        object fileName = "F:\\周老师\\毕业设计\\QE_WebSites\\UpLoad";
        Microsoft.Office.Interop.Word.Document doc = (Microsoft.Office.Interop.Word.Document)docsType.InvokeMember("Open",
             System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { fileName, true, true });
        // 转换格式,另存为   
        Type docType = doc.GetType();
        object saveFileName = Server.MapPath("../Upload/") + documentName1 + ".html";
        ClientScript.RegisterStartupScript(Page.GetType(), "", "<script language=javascript>window.opener=null;window.open('','_self');window.close();</script>");

        //保存HTML  
        docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Word.WdSaveFormat.wdFormatHTML });
        // 退出 Word   
        wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
        //跳转显示预案信息  
        Response.Redirect("../Upload/" + documentName1 + ".html");  
    }
}请各位帮帮忙看看!谢谢! --------------------编程问答--------------------
引用 楼主 clbynicai 的回复:
为什么我在网站中调试的时候出现错误
在浏览器中显示的是Word 在试图打开文件时遇到错误。
请尝试下列方法:
* 检查文档或驱动器的文件权限。
* 确保有足够的内存和磁盘空间。
* 用文本恢复转换器打开文件。 (F:\周老师\毕业设计\QE_WebSites\UpLoad\)
在代码中显示的错误如下图


代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using USTC;
using Word = Microsoft.Office.Interop.Word;
using System.Data.SqlClient;
using System.Data;
using System.Diagnostics;


public partial class Inform_QE_Word : System.Web.UI.Page
{
    DbManager db = new DbManager();
    public string countyName = string.Empty; //乡镇名称  
    public string documentFullName = string.Empty; //预案全称(包括后缀名)  
    public string documentName1 = string.Empty; //预案名称  
    protected void Page_Load(object sender, EventArgs e)
    {
        //GetData();
        //GetGoodsInfo();
        if (!IsPostBack)
        {
            try
            {
                //根据传递过来的乡镇名称获取到文件名称  
                countyName = Server.UrlDecode(Request.QueryString["id"].ToString().Trim());
                DM dm = new DM();
                string strSQL = "select documentName from QE_Inform";
                documentFullName = dm.getsql(strSQL).Tables[0].Rows[0]["documentName"].ToString().Trim();
                documentName1 = documentFullName.Substring(0, documentFullName.LastIndexOf('.'));
            }
            catch (Exception)
            {
                documentFullName = "";
            }
        }
        // 在此处放置用户代码以初始化页面   
        Word.ApplicationClass word = new Word.ApplicationClass();
        Type wordType = word.GetType();
        Word.Documents docs = word.Documents; // 打开文件   
        Type docsType = docs.GetType();
        object fileName = "F:\\周老师\\毕业设计\\QE_WebSites\\UpLoad";
        Microsoft.Office.Interop.Word.Document doc = (Microsoft.Office.Interop.Word.Document)docsType.InvokeMember("Open",
             System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { fileName, true, true });
        // 转换格式,另存为   
        Type docType = doc.GetType();
        object saveFileName = Server.MapPath("../Upload/") + documentName1 + ".html";
        ClientScript.RegisterStartupScript(Page.GetType(), "", "<script language=javascript>window.opener=null;window.open('','_self');window.close();</script>");

        //保存HTML  
        docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Word.WdSaveFormat.wdFormatHTML });
        // 退出 Word   
        wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
        //跳转显示预案信息  
        Response.Redirect("../Upload/" + documentName1 + ".html");  
    }
}请各位帮帮忙看看!谢谢!


NULL????
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,