保存对话框以下载文件,将文件从 ASP.NET 服务器保存到客户端

Save dialog box to download file, Saving file from ASP.NET server to the client(保存对话框以下载文件,将文件从 ASP.NET 服务器保存到客户端)

本文介绍了保存对话框以下载文件,将文件从 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 服务器保存到客户端

基础教程推荐