Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want when i click a nutton in ASP.NET the file is downloaded to my computer, i want a code in ASP.NET C# to implement this , also about how can the file is made accessible to download,i mean where the file is put to download?
Posted

The file could be in a directory/ virtual directory in your server. In a link button have a link of the virtual path pointing the file. If you click the link in the browser the file will get download.
 
Share this answer
 
Comments
muntahach 28-Apr-11 14:24pm    
please explain a little, i did it but it is not working
Albin Abel 28-Apr-11 15:48pm    
show me what you did, we could start from there.
Albin Abel 28-Apr-11 15:51pm    
Also provide information is there is any error.
Sergey Alexandrovich Kryukov 28-Apr-11 22:36pm    
My 5.
--SA
Albin Abel 28-Apr-11 23:38pm    
Thanks SAKryukov. Waiting for Op to respond.
Use this code
MIDL
string filename = "site.css";// Need actual filename with extension E.g site.css
       Response.ContentType = "application/octet-stream";
       Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename);
       Response.BinaryWrite(System.IO.File.ReadAllBytes(Server.MapPath("~/styles/" + filename)));
       Response.End();
 
Share this answer
 
File Upload and Download in ASP.NET[^]

have a look on that, Hope this can help you.
 
Share this answer
 
Comments
muntahach 28-Apr-11 14:25pm    
i check it but it gives error
string filename = "BOOK PURCHASE REQUEST FORM Final";
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename);
string aaa = Server.MapPath("~/SavedFolder/" + filename);
Response.TransmitFile(Server.MapPath("~/SavedFolder/" + filename));
Response.End();


i use this code but it gives error in 2nd last line
velvet7 28-Apr-11 15:05pm    
Please explain that error more deatailed.

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