Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
how to make a download button in  asp.net? Am using fllowing code It's Not working.

 try
            {

             string date = DateTime.Now.ToShortDateString();
             string newdate = date.Replace("/", ".");
             string filePath = Server.MapPath("~/C:/HKGOUTBOUND/" + newdate + ".TXT");
                string FileName = "" + newdate + ".TXT";

      Response.ContentType = "Application/TXT";
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + FileName + "\"");
      Response.TransmitFile(Server.MapPath("~/C:/HKGOUTBOUND/"+ newdate + ".TXT"));
                Response.End();

            }
            catch (Exception)
            {

                throw;
            }


Any one Can help me. Thank you.
Posted
Comments
Sergey Alexandrovich Kryukov 5-Aug-14 3:02am    
The button is already made... :-)
—SA
[no name] 5-Aug-14 4:52am    
but not Download the file

1 solution

Modified your code.
string date = DateTime.Now.ToShortDateString();
            string newdate = date.Replace("/", ".");
            string filePath = Server.MapPath("~/C:/HKGOUTBOUND/" + newdate + ".TXT");
            string FileName = newdate + ".TXT";

            Response.ContentType = "Application/TXT";
            Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName + ";");
            Response.TransmitFile(Server.MapPath("~/C:/HKGOUTBOUND/" + newdate + ".TXT"));
            Response.Flush();
            Response.End();
 
Share this answer
 
Comments
[no name] 5-Aug-14 2:20am    
successfully debug but not Download the File.
Member 10987102 5-Aug-14 2:40am    
problem may be file location.please check the file location.
[no name] 5-Aug-14 3:09am    
Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack. pop up this exception

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