/// 使用WriteFile下载文件
/// </summary>
/// <param name="filePath">相对路径</param>
public void WriteFile(string filePath)
{
try
{
string _pre_path = filePath;
filePath = Server.MapPath(filePath);
if (File.Exists(filePath))
{
FileInfo info = new FileInfo(filePath);
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment;filename=" + _pre_path.Replace("~/Upload/BidFile/", ""));
Response.AddHeader("Content-Length", info.Length.ToString());
Response.AddHeader("Content-Transfer-Encoding", "binary");
Response.ContentType = "application/octet-stream";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
Response.WriteFile(info.FullName);
Response.Flush();
Response.End();
}
}
catch
{ }
finally
{
HttpContext.Current.Response.Close();
}
}
ASP.NET WriteFile下载文件
最新推荐文章于 2024-04-17 09:17:19 发布