public static void FileDownload(string FullFileName)
{
//FileInfo Driver_Path = new FileInfo(FullFileName);
string Driver_Path=HttpContext.Current.Server.MapPath(".")+"\\DownLoad\\"+FullFileName;
if (!File.Exists(Driver_Path))
{
HttpContext.Current.Response.Write("");
return;
}
try
{
FileInfo file1 = new FileInfo(Driver_Path);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.Buffer = false;
string strHadFileName = System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(Driver_Path));
HttpContext.Current.Response.AddHeader("Content-Type","application/octet-stream");
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + strHadFileName); //下载到客户端默认文件名
// 可以看到下载进程
HttpContext.Current.Response.AddHeader("Content-Length", file1.Length.ToString());
string strFullName = file1.FullName;
HttpContext.Current.Response.WriteFile(strFullName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
catch
{
}
}
调用:
private void Button2_Click(object sender, System.EventArgs e)
{
string file1="API_IDECL_DBF.mdb";
Interface.FileDownload(file1);
}
(上述出自:)
阅读(1604) | 评论(0) | 转发(0) |