ASP.NET 下载文件代码块

/// <summary>
/// 普通下载
/// </summary>
/// <param name="FileName">文件虚拟路径</param>
public static void DownLoadold(string FileName)
{
    string destFileName = FileName; //MapPathFile(FileName);
    if (File.Exists(destFileName))
    {
        FileInfo fi = new FileInfo(destFileName);
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.ClearHeaders();
        HttpContext.Current.Response.Buffer = false;
        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Path.GetFileName(destFileName), System.Text.Encoding.UTF8));
        HttpContext.Current.Response.AppendHeader("Content-Length", fi.Length.ToString());
        HttpContext.Current.Response.ContentType = "application/octet-stream";
        HttpContext.Current.Response.WriteFile(destFileName);
        HttpContext.Current.Response.Flush();
        HttpContext.Current.Response.End();
    }
}

posted @ 2013-04-19 14:30  zhenpingwang  阅读(256)  评论(0)    收藏  举报