日期:2014-05-19  浏览次数:20550 次

下载问题
请问是否能通过一个BUTTON按钮来下载某个文件夹下的某个文件

------解决方案--------------------
可以,在这个按钮事件里写上 Response.Redirect( "http://localhost/down/xxx.exe ");
这个down就是你建立的虚拟目录到某个文件夹下,xxx.exe就是那个文件夹下面的某个文件哈
------解决方案--------------------
if (!System.IO.File.Exists(MapPath( "文件路径 ")))
{
Response.Write( " <script language= 'javascript '> alert( '对不起,文件不存在! '); </script> ");
return;
}
Response.Clear();
Response.ClearHeaders();
Response.Charset = "GB2312 ";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.ContentType = "application/octet-stream ";
FileInfo fi = new FileInfo(MapPath( "文件路径 "));
Response.AddHeader( "Content-Disposition ", "attachment; filename= " + HttpUtility.UrlEncode(fi.Name));
Response.AddHeader( "Content-Length ", fi.Length.ToString());
byte[] tmpbyte = new byte[1024 * 8];
FileStream fs = fi.OpenRead();
int count;
while ((count = fs.Read(tmpbyte, 0, tmpbyte.Length)) > 0)
{
Response.BinaryWrite(tmpbyte);
Response.Flush();
}
fs.Close();
Response.End();