/// <summary>
    /// 下载文件
    /// </summary>
    /// <param name="vPath">文件路径(绝对路径)</param>
    public static void DownloadData(string path)
    {
        if (File.Exists(path))
        {
            FileInfo DownloadFile = new FileInfo(path);
            System.Web.HttpContext.Current.Response.Clear();
            System.Web.HttpContext.Current.Response.ClearHeaders();
            System.Web.HttpContext.Current.Response.Buffer = false;
            System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
            System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
            System.Web.HttpContext.Current.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
            System.Web.HttpContext.Current.Response.WriteFile(DownloadFile.FullName);
            System.Web.HttpContext.Current.Response.Flush();
            System.Web.HttpContext.Current.Response.End();
        }
        else
        {
            throw new Exception("提示:下载失败,找不到该文件");
        }
    }

相关文章:

  • 2021-07-18
  • 2022-02-26
  • 2022-12-23
猜你喜欢
  • 2021-06-13
  • 2021-11-24
  • 2021-05-25
  • 2021-07-23
  • 2021-09-12
相关资源
相似解决方案