Download file from FTP and how prompt user to save/open file in ASP.NET C#

后端 未结 1 904
时光取名叫无心
时光取名叫无心 2021-01-15 19:06

Download file from FTP and how prompt user to save/open file in ASP.NET C#

string strDownloadURL = System.Configuration.ConfigurationSettings.AppSettings[\"D         


        
1条回答
  •  抹茶落季
    2021-01-15 19:26

    So, assuming you're writing the FTP request's response stream down to the ASP.NET response stream, and want to trigger the download dialog in the browser, you'll want to set the Content-Disposition header in the response.

    // note: since you are writing directly to client, I removed the `file` stream
    // in your original code since we don't need to store the file locally...
    // or so I am assuming
    Response.AddHeader("content-disposition", "attachment;filename=" + strFile);
    
    byte[] buffer = new byte[2 * 1024];
    int read;
    while ((read = responseStream.Read(buffer, 0, buffer.Length)) > 0) 
    { 
       Response.OutputStream.Write(buffer, 0, read);
    }
    
    responseStream.Close();
    response.Close();
    

    0 讨论(0)
提交回复
热议问题