UPhttp://expert.csdn.net/Expert/topic/1153/1153814.xml?temp=.3446619
解决方案 »
- ashx是什么文件有什么用
- 看了几个商业版的asp.net程序 有一个疑问
- 如何在javascript动态生成的iframe的src中加入绑定表达式
- ASP.NET+AJAX解决网页打开等待问题
- 新增的时候,如何让时间输入框默认为当前时间,且格式为年月日,没有时分秒,我用的ASP.NET2.0+MS SQL Server
- 文件下载的问题
- 兄弟们,新年好,先在这里高散分了,给大家发红包了
- 急急,怎么样动态编辑treeview的结点值
- 在水晶报表中,我采用push模式连接多个表,怎么会出现登陆错误??(急死我了!!)
- 如何在自定义的类中获得客户端IP?
- 关于datatable新增column的问题
- 各位请看这个小case,给小弟个方!
Response.BinaryWrite
Dim ImgID = Request.QueryString("ImgID")
Dim con As SqlClient.SqlConnection
'查询sql
Dim str = Context.GetConfig("appSettings")("dsn")
con = New SqlConnection(str)
Dim SqlCmd = "SELECT * from 多文档信息表 where 文档编号='" & ImgID & "'"
con.Open()
Dim ada As New SqlClient.SqlDataAdapter(SqlCmd, con)
Dim ds As New DataSet()
ada.Fill(ds, "wendang") '设定输出文件类型
'Response.AddHeader("Content-Disposition", "attachment; filename=" & ds.Tables(0).Rows(0).Item("文件名称"))
Response.ContentType = Trim(ds.Tables(0).Rows(0).Item("文档类型"))
'输出图象文件二进制数制
Dim FileByteArray() As Byte = ds.Tables(0).Rows(0).Item("文档内容")
Dim s = ds.Tables(0).Rows(0).Item("文档内容")
s = FileByteArray.Length
Response.OutputStream.Write(ds.Tables(0).Rows(0).Item("文档内容"), 0, CInt(s))
con.Close()
// Response.ContentType="Application/x-msexcel";Response.ContentType="Application/msword";this.Response.Clear();
Handler.SqlBlobToFile(Session["file"].ToString(),DBcon,this.Response.OutputStream);
this.Response.End();
下面是SqlBlobToFile函数的实现:
////////////////////////////////////////////////////////////////////////////
public static bool SqlBlobToFile(string fileName,string ConString, System.IO.Stream fs)
{
bool bresult=true; try
{
int fileDataCol = 0;
SqlConnection cn=new SqlConnection(ConString);
SqlCommand cmd=new SqlCommand(@"SELECT fileData FROM imagefile WHERE filename='"+fileName +@"'",cn);
cn.Open(); SqlDataReader dr=cmd.ExecuteReader();
dr.Read();
Byte[] b = new Byte[(dr.GetBytes(fileDataCol, 0, null, 0, int.MaxValue))];
dr.GetBytes(fileDataCol, 0, b, 0, b.Length);
dr.Close();
cn.Close(); fs.Write(b,0,b.Length);
fs.Close();
} catch(SqlException ex)
{
bresult=false;
} return bresult;}
Response.BinaryWrite(byte[]...);
Response.End();这样来下载不会出错。
Byte[] b=new Byte[dbRead.GetBytes(2,0,null,0,int.MaxValue)];
dbRead.GetBytes(2,0,b,0,b.Length);
Response.BinaryWrite(b);
或者:
Byte[] b=new Byte[dbRead.GetBytes(2,0,null,0,int.MaxValue)];
dbRead.GetBytes(2,0,b,0,b.Length);
Response.OutputStream.Write(b,0,b.Length);