javascript里面      

<script type="text/javascript">

       var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_initializeRequest(downloadfile);
        //触发函数
        function downloadfile(filepath) {
            var iframe = document.createElement("iframe");
            iframe.src = "GenerateFile.aspx?filepath=" + filepath;
            iframe.style.display = "none";
            document.body.appendChild(iframe);
        }
    </script>

      <body>

    <a onclick="downloadfile('filepath') download</a>

  </body>

 

    public partial class GenerateFile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string fileResponse="file content";
            string filepath = Request.QueryString["filepath"];
            Response.AddHeader("Content-disposition", "attachment; filename=report.csv");
            Response.ContentType = "application/octet-stream";
            Response.Write(fileResponse);
            Response.End();

        }
    }

相关文章:

  • 2022-02-11
  • 2021-06-07
  • 2021-10-22
  • 2021-07-26
  • 2022-12-23
  • 2021-08-31
  • 2021-12-16
猜你喜欢
  • 2022-12-23
  • 2021-07-27
  • 2021-06-06
  • 2022-12-23
  • 2022-01-28
  • 2022-12-23
  • 2021-11-18
相关资源
相似解决方案