Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Use of download ability in my web site
Hi
I have web site . I wants to put this ability to my site for download a zip file from my site.
I know how upload files. But I don’t know the source code for download. (by c#)
Thanks very much
Posted

1 solution

Here is the sample code to download a file using ASP .NET

C#
try
{
   System.String filename = "myFile.txt";

   // set the http content type to "APPLICATION/OCTET-STREAM
   Response.ContentType = "APPLICATION/OCTET-STREAM";
   
   // initialize the http content-disposition header to
   // indicate a file attachment with the default filename
   // "myFile.txt"
   System.String disHeader = "Attachment; Filename=\"" + filename +
      "\"";
   Response.AppendHeader("Content-Disposition", disHeader);

   // transfer the file byte-by-byte to the response object
   System.IO.FileInfo fileToDownload = new
      System.IO.FileInfo("C:\\download\\myFile.txt");
   Response.Flush();
   Response.WriteFile(fileToDownload.FullName);}
catch (System.Exception e)
// file IO errors
{
   SupportClass.WriteStackTrace(e, Console.Error);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900