Save dialog box to download file, Saving file from ASP.NET server to the client(保存对话框以下载文件,将文件从 ASP.NET 服务器保存到客户端)
问题描述
我一直在互联网上搜索,但找不到任何有用的答案.
I've been searching around the internet, but couldn't find any useful answer.
我有一个 ASP.NET 网站,它部署在服务器上.服务器上的 ASP.NET 网站可以访问名为 W:/的目录.公司的客户可以访问该网站.该网站在 ListBox 中列出了 W:/目录中的所有 PDF 文件.客户端应该能够从列表框中选择 PDF 文件,并通过为其选择位置将它们保存到本地 PC.
I have an ASP.NET web site, which is deployed on server. The ASP.NET web site on the server can access a directory called W:/ . The clients in the company can access the web site. The web site lists in a ListBox all the PDF files from the W:/ directory. The client should be able to select PDF files from the listbox and save them to it's local PC by selecting a location for it.
类似于在网页上另存为文件.
Something like save as file on web pages.
您能否提供一些解决方案或解决方法?
Could you provide me some solution or work around ?
推荐答案
终于找到一篇文章,提示保存对话框从 ASP.NET 下载文件
Finally I've found an article, which Prompts a Save Dialog Box to Download a File from ASP.NET
我把它贴在这里,也可以帮助其他人并节省一些时间.
I post it here, might help somebody else as well and save some time.
String FileName = "FileName.txt";
String FilePath = "C:/...."; //Replace this
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "text/plain";
response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
response.TransmitFile(FilePath);
response.Flush();
response.End();
这篇关于保存对话框以下载文件,将文件从 ASP.NET 服务器保存到客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:保存对话框以下载文件,将文件从 ASP.NET 服务器保存到客户端


基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01