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

纵饮孤独 提交于 2019-12-01 12:38:40
HackedByChinese

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();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!