下载文件(简洁方法)

   public static void DownLoadFile(HttpRequest _Request, HttpResponse _Response, string fileName, string fullPath)
    {
        FileInfo fileInfo = new FileInfo(fullPath);
        if (fileInfo.Exists)
        {
            _Response.Clear();
            _Response.ClearHeaders();
            _Response.Buffer = false;
            _Response.ContentType = "application/octet-stream";
            _Response.ContentEncoding = Encoding.UTF8;
            _Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
            _Response.AppendHeader("Content-Length", fileInfo.Length.ToString());
            _Response.TransmitFile(fullPath, 0L, fileInfo.Length);
            _Response.WriteFile(fileInfo.FullName);
            _Response.Flush();
            _Response.End();
            _Response.Close();
        }
    }

 

posted on 2014-08-13 14:31  小景  阅读(164)  评论(0编辑  收藏  举报