Kunal Bhajbhuje

Kunal Bhajbhuje

  • NA
  • 16
  • 382

How to use Linkbutton control to download the document ?

Mar 11 2019 2:17 AM
My code so far...
  1. protected void LinkButton3_Click(object sender, EventArgs e)  
  2. {  
  3. string filename = “~/Users/Kunal/Desktop/Website EasyGo Email/EasyMon Specifications_Rev1.1.pdf”;  
  4. if (filename != “”)  
  5. {  
  6. string path = Server.MapPath(filename);  
  7. System.IO.FileInfo file = new System.IO.FileInfo(path);  
  8. if (file.Exists)  
  9. {  
  10. Response.Clear();  
  11. Response.AddHeader(“Content-Disposition”, “attachment; filename=” +filename);  
  12. Response.AddHeader(“Content-Length”, file.Length.ToString());  
  13. Response.ContentType = “EasyMon Specifications_Rev1.1.pdf”;  
  14. Response.WriteFile(file.FullName);  
  15. Response.End();  
  16. }  
  17. else  
  18. {  
  19. Response.Write(“This file does not exist.”);  
  20. }  
  21. }  
  22. }  

Answers (2)