我用一个GridView的  HyperLinkField 项指定一个页面显示某个上传的文件(不同的人有不同的文件).
当此文件为.txt格式时能正常显示,当为.doc格式时就出现如下错误.为什么呢?    (vs2005+asp.net+sql)无法显示 XML 页。 
使用 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。 
--------------------------------------------------------------------------------文本内容中发现无效字符。处理资源 'http://localhost:1390/复件%20复件%20management/showjianli.aspx?ID=刘馨' 时出错。第 1 行,位置: 3 
 

解决方案 »

  1.   

    有中文。修改xml的编码方式就可以了。
      

  2.   

    可是为什么 txt格式的  能正常显示呢?
      

  3.   

    <?xml version="1.0" encoding="gb2312"?>
      

  4.   

    你把xml用notpad右键打开,看是是不是用ansi存的啊?改成utf-8吧。你的text可能是用utf-8存的,所以没问题。编码这东西,我也没太明白。只是你这个问题,我遇到过两次,就是改改编码,换下文件的格式搞定的。对不起啊,我没办法给你准确答案
      

  5.   

    如果你的xml是用aspx动态生成的话,记得要修改content-type的。微软默认的编码是会把中文搞乱码的。
      

  6.   

    xml用notpad右键打开
    哪个文件呐,呵呵.我是新手啊,不懂多少的.刚才那个我是打开aspnet.config看到那个xml的编码方式的.
      

  7.   

    如果XML节点值中有中文的话,要使用<!CDATA[内容]]>另外设置一下 Response.ContentType = "text/xml";
      

  8.   

    应该是showjianli.aspx的编码有问题。
    你去这个页面,设置他的Content-Type就可以了.你的没有xml文件,xml是动态生成的。
      

  9.   

       <!CDATA[内容]]> 是什么,在哪里?
      

  10.   


    我改了以后,连那个txt格式的都出错了,我是按照8楼改的.不过我没使用  <!CDATA[内容]]>  ,因为不知道 那个是什么,在哪里.呵呵.
      

  11.   

    showjianli.aspx的头部要这样设置
    <Meta http-equiv="Content-Type" Content="text/html; Charset=gb2312">这样设置.txt会出错?
      

  12.   

    前面说的修改xml的编码是针对xml是本来就存在的情况。
    你的xml是生成的。
    <head runat="server">
       <!-- 在Head里面添加这么一行 -->    
       <Meta http-equiv="Content-Type" Content="text/html; Charset=gb2312">
    </head>
      

  13.   

    或者发项目到位邮箱,我看能不能帮你改改。如果你本身就是改别人的代码,那就算了。[email protected]
      

  14.   

        好长的,第一个页面就是一个GridView.  添加一个HyperLinkField 项,指定一个页面显示某个上传的文件
          其DataNavigateURLFormatString属性为: showjianli.aspx?ID={0}
        protected void Page_Load(object sender, EventArgs e)
        {        string ID = Request["ID"].ToString();
            Label1.Text = ID;
            Label1.Visible = false;
            SqlConnection meteor = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["meteor"]);
            meteor.Open();        SqlCommand comm = new SqlCommand("select uploadfile from studentinformation where studentname ='" + Label1.Text.ToString().Trim() + "'", meteor);        SqlDataReader dr = comm.ExecuteReader();        string tmp;
            if (dr.Read())
            {
                tmp = dr["uploadfile"].ToString();
                if (tmp.Length > 0)
                {
                    show();
                }
                else
                {
                    Response.Write("<script language=javascript>alert('对不起,该生简历不存在!');window.close()</script>");
                }
            }         meteor.Close();
        }
        private void show()
        {
            SqlConnection meteor = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["meteor"]);
            meteor.Open();
            SqlCommand comm = new SqlCommand("select * from studentinformation where studentname ='" + Label1.Text.ToString().Trim() + "'", meteor);
            SqlDataReader dr = comm.ExecuteReader();
            if (dr.Read())
            {
                Label2.Text = dr.GetString(17);
                Label2.Visible = false;
            }
            meteor.Close();        string strFileUploadPath = Server.MapPath("~/upload/");
            string strFileName = Label2.Text;
            string FullFileName = strFileUploadPath + strFileName;
            FileInfo DownloadFile = new FileInfo(FullFileName);
            Response.Clear();
            Response.ClearHeaders();
            Response.Buffer = false;
            Response.ContentType = "application/octet-stream ";
            Response.AppendHeader("Content-Disposition ", "attachment;filename= "
                + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
            Response.AppendHeader("Content-Length ", DownloadFile.Length.ToString());
            Response.WriteFile(DownloadFile.FullName);
            Response.Flush();
            Response.End();    }
      

  15.   

    我解决不了,对不起俄。
    如果要直接显示word,好像需要插件支持。还是等别人把。对不起。FileInfo DownloadFile = new FileInfo(Server.MapPath(string.Format("~/{0}.doc", Label1.Text )));
                Response.Clear();
                Response.ClearHeaders();
                Response.Buffer = false;
             // Response.ContentType = "application/octet-stream ";
                Response.ContentType = "application/msword";
                //Response.AppendHeader("Content-Disposition ", "attachment;filename= "
                //    + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
                Response.AppendHeader("Content-Length ", DownloadFile.Length.ToString());
                Response.WriteFile(DownloadFile.FullName);       
                Response.End();