//文件下载 |
protected void FileAction( object source, RepeaterCommandEventArgs e) |
{ |
switch (e.CommandName) |
{ |
case "DownTemp" : |
int downID = Utility.getVal(e.CommandArgument); |
DataSet ds = Common.NoPager2( "Std_BZFiles" , "" , "ID,FileName,FileUrl" , "" , "ID='" + downID + "'" ); |
string strFilePhysicalPath = ds.Tables[0].Rows[0][ "FileUrl" ].ToString(); |
int start = strFilePhysicalPath.LastIndexOf( "." ) + 1; |
int total = strFilePhysicalPath.Length - strFilePhysicalPath.LastIndexOf( "." ) - 1; |
string FileUrl = ds.Tables[0].Rows[0][ "FileUrl" ].ToString(); |
int k = FileUrl.LastIndexOf( "\\" ); |
string strFileName = FileUrl.Substring(k + 37); |
//清空输出流 |
Response.Clear(); |
//在HTTP头中加入文件名信息 |
Response.AddHeader( "Content-Disposition" , "attachment;FileName=" + HttpUtility.UrlEncode(strFileName, System.Text.Encoding.UTF8)); |
//定义输出流翸IME类型为 |
Response.ContentType = "application/octet-stream" ; |
//从磁盘读取文件流 |
System.IO.FileStream fs = System.IO.File.OpenRead(strFilePhysicalPath); |
//定义缓冲区大洙小 |
byte [] buffer = new byte [102400]; |
//第台?一?次?读á取? |
int i = fs.Read(buffer, 0, buffer.Length); |
//如果读取的字节大于,则使用BinaryWrite()不断向客户端输出文件流 |
while (i > 0) |
{ |
Response.BinaryWrite(buffer); |
i = fs.Read(buffer, 0, buffer.Length); |
} |
//关闭磁盘文件流 |
fs.Close(); |
//关闭输出流 |
Response.End(); |
break ; |
default : |
break ; |
} |
} |
by: 发表于:2018-01-03 10:44:10 顶(0) | 踩(0) 回复
??
回复评论