ASP.NET:创建 CSV 并将文件保存在客户端计算机上
要求:我有一个 ASP.NET 应用程序,其中页面在 gridview 中显示数据。此表单还有一个文本框,将文件路径作为输入,旁边有一个保存按钮。现在,当用户单击“保存”时,csv 应将其保存在客户端计算机上用户输入的路径中。
我尝试使用“内容处置附件文件名”打开“另存为”对话框。但它总是在默认路径上打开。有没有办法在用户特定的路径上打开此“另存为”对话框。
还有其他方法在服务器上创建文件并将其复制到客户端计算机吗?
请建议。
-贾斯汀·塞缪尔。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于安全限制,这是无法完成的。让用户下载 CSV 并自行选择位置。
This cannot be done, because of security restriction. Let the user download the CSV and choose the location on his own.
如果您尝试强制下载始终提供“另存为”,则应将
content-type
设置为application/octet-stream
。但是,出于安全原因,始终由用户决定该文件的保存位置。If you are trying to force the download to always give a Save As, you should set the
content-type
toapplication/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.