文件下载 - FileGetDownload

2017-01-26 09:26:37  访问(4985) 赞(0) 踩(0)


        /// <summary>
        /// 文件下载
        /// </summary>
        /// <param name="filePath">文件路径</param>
        public void FileGetDownload(string filePath)
        {
            string strName = Path.GetFileName(filePath);

            FileInfo downloadFile = new FileInfo(filePath);

            if (downloadFile.Exists)
            {
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.ClearHeaders();
                HttpContext.Current.Response.Buffer = false;
                HttpContext.Current.Response.ContentType = "application/octet-stream";
                HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + strName);
                HttpContext.Current.Response.AppendHeader("Content-Length", downloadFile.Length.ToString());
                HttpContext.Current.Response.WriteFile(downloadFile.FullName);
            }

            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
        }


标签:文件下载 - FileGetDownload 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)