ASP.net download and save file in user folder

此生再无相见时 提交于 2019-12-07 02:52:27

You can't force the place the file is downloaded to.

In your code, you shouldn't write to file, but to the OutputStream from the response.

RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);

HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=\"file.pdf\"");
HttpContext.Current.Response.OutputStream.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);

Filestream will write to a file on server and not on the client's machine.

Try writing the document bytes to response output stream and a content-disposition http header to response.

Response.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");

This would prompt user for the file download based on browser setting.

You cannot control which directory file goes in in the client's machine.

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