我用一个GridView的 HyperLinkField 项指定一个页面显示某个上传的文件(不同的人有不同的文件).
当此文件为.txt格式时能正常显示,当为.doc格式时就出现如下错误.为什么呢? (vs2005+asp.net+sql)无法显示 XML 页。
使用 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。
--------------------------------------------------------------------------------文本内容中发现无效字符。处理资源 'http://localhost:1390/复件%20复件%20management/showjianli.aspx?ID=刘馨' 时出错。第 1 行,位置: 3
当此文件为.txt格式时能正常显示,当为.doc格式时就出现如下错误.为什么呢? (vs2005+asp.net+sql)无法显示 XML 页。
使用 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。
--------------------------------------------------------------------------------文本内容中发现无效字符。处理资源 'http://localhost:1390/复件%20复件%20management/showjianli.aspx?ID=刘馨' 时出错。第 1 行,位置: 3
解决方案 »
- 50分求ASP.NET整合UCenter同步登陆DZ和UChome示例代码
- 急救。。。菜单被页面藏住了。。。
- 远程访问MessageBox为什么会出错?
- 【求解】session无故超时,会话只持续20秒钟
- 求DataTable导出到pdf的代码
- Server.Transfer 传值问题
- 关于SEQUENCE的SQL语法问题
- 求验证表达式:如1,100.41
- 跪求ASP.NET+C#开发实例
- .net 提示 div 的 style="overflow-y" 不是有效的 css 属性名?
- GridView用ObjectDataSource的时候包含DropDownList列时的更新问题
- jquery 中如何调用后台传过来的值啊?
哪个文件呐,呵呵.我是新手啊,不懂多少的.刚才那个我是打开aspnet.config看到那个xml的编码方式的.
你去这个页面,设置他的Content-Type就可以了.你的没有xml文件,xml是动态生成的。
我改了以后,连那个txt格式的都出错了,我是按照8楼改的.不过我没使用 <!CDATA[内容]]> ,因为不知道 那个是什么,在哪里.呵呵.
<Meta http-equiv="Content-Type" Content="text/html; Charset=gb2312">这样设置.txt会出错?
你的xml是生成的。
<head runat="server">
<!-- 在Head里面添加这么一行 -->
<Meta http-equiv="Content-Type" Content="text/html; Charset=gb2312">
</head>
其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(); }
如果要直接显示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();