无法显示 XML 页
我用一个GridView的 HyperLinkField 项指定一个页面显示某个上传的文件(不同的人有不同的文件).当此文件为.txt格式时能正常显示,当为.doc格式时就出现如下错误.为什么呢? (vs2005+asp.net+sql)
无法显示 XML 页。
使用 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。
--------------------------------------------------------------------------------
文本内容中发现无效字符。处理资源 'http://localhost:1390/复件%20复件%20management/showjianli.aspx?ID=刘馨' 时出错。第 1 行,位置: 3
代码呢?
是将文件读到网页中吗? 是啊,是将已经上传过的文件显示在网页中.我的代码是这样的.
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();
} Response.ContentType="application/msword"; 呵呵,谢了哦.可以了.多谢!
页:
[1]
