Save dialog box to download file, Saving file from ASP.NET server to the client

user1734609 picture user1734609 · Oct 11, 2012 · Viewed 45.1k times · Source

I've been searching around the internet, but couldn't find any useful answer.

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 ?

Answer

user1734609 picture user1734609 · Oct 11, 2012

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();