ASP.NET: Create CSV and save file on client machine

蓝咒 提交于 2020-01-06 05:49:04

问题



Requirement: I have an ASP.NET application where a page has data displayed in gridview. This form also has a textbox which takes filepath as input, with a save button beside it. Now when the user clicks on save the csv should save it on client machine at the path the user entered.

I tried opening up a SaveAs Dialogbox using the "Content-Disposition attachment filename". But it always opens up on its default path. Is there a way to open up this SaveAs Dialog on user-specific path.

Else is there any other way of creating file on server and copying it to client machine?

Please suggest.

-Justin Samuel.


回答1:


This cannot be done, because of security restriction. Let the user download the CSV and choose the location on his own.




回答2:


If you are trying to force the download to always give a Save As, you should set the content-type to application/octet-stream. However, it will always be up to the user to decide where that file is saved and that is as it should be for security reasons.



来源:https://stackoverflow.com/questions/6083032/asp-net-create-csv-and-save-file-on-client-machine

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