Save dialog box to download file, Saving file from ASP.NET server to the client

前端 未结 5 948
谎友^
谎友^ 2020-12-01 21:59

I\'ve been searching around the internet, but couldn\'t find any useful answer.

I have an ASP.NET web site, which is deployed on server. The ASP.NET web site on the

5条回答
  •  伪装坚强ぢ
    2020-12-01 22:39

    This is an extension to user1734609's solution that gets a file locally.

    To download a file from the server to client:

    public void DownloadFile()
            {
                String FileName = "201604112318571964-sample2.txt";
                String FilePath = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/Uploads/" + FileName;
                System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
                response.ClearContent();
                response.Clear();
                response.ContentType = "text/plain";
                response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
                response.TransmitFile(FilePath);
                response.Flush();
                response.End();
    
    
            }
    

提交回复
热议问题