asp.net varbinary(MAX) 类型字段,保存任意文件,下载时出错。
代码:
DataBaseClass db = new DataBaseClass();
string sSqlText = "select fileContent from T_FileLists WHERE id=3";
SqlConnection con = new SqlConnection(db.sConString);
con.Open();
SqlCommand cmd = new SqlCommand(sSqlText, con);
SqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
string fileName = "bbb.doc";
if (dr.Read())
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "utf-8";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName); //把 attachment 改为 online 则在线打开
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
Response.ContentType = "application/octet-stream";
Response.BinaryWrite((byte[])dr[0]);
}
con.Close(); 出错:
代码:
DataBaseClass db = new DataBaseClass();
string sSqlText = "select fileContent from T_FileLists WHERE id=3";
SqlConnection con = new SqlConnection(db.sConString);
con.Open();
SqlCommand cmd = new SqlCommand(sSqlText, con);
SqlDataReader dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
string fileName = "bbb.doc";
if (dr.Read())
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "utf-8";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName); //把 attachment 改为 online 则在线打开
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
Response.ContentType = "application/octet-stream";
Response.BinaryWrite((byte[])dr[0]);
}
con.Close(); 出错:
解决方案 »
- 怎样发现在datalist中的Repeater控件?
- 小弟有一个问题:一个静态页,里面一个input输入年份,一个input点击可转到年份的页面,小弟不知道如何根据input中的值转到固定页面,说不清楚,请看代码!
- 主页面刷新后用户控件中的属性没有得到赋值,怎么办?
- 如何设定SESSION 周期?
- Http代理能够实现这样的功能吗?
- 超过10万条纪录的txt文件无法上传?
- 帮帮忙,iis不能启动了.很急
- Repeater control: 怎样换行?
- ASP.NET怎样上传文件到Oracle数据库,文件文件字段类型为BLOB?
- asp:FileUpload上传文件怎么加载进度条?详细点,谢谢
- 关于datetime为null的时候报错
- 求一款开源cms~~~标题要长~~~~~~~
Response.Clear();
Response.Buffer = true;
Response.ContentType = "text/richtext";
Response.AddHeader("content-disposition", "attachment; filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8) + ";size=0");
Response.Write(sb.ToString());
Response.Flush();
Response.End();