Showing posts with label Asp.net C# code for download file. Show all posts
Showing posts with label Asp.net C# code for download file. Show all posts

Sunday, May 24, 2015

Asp.net C# code for download file


  protected void DownloadFile(string Path, string FileName)  
   {  
     try  
     {  
       string strURL = Path;  
       WebClient req = new WebClient();  
       HttpResponse response = HttpContext.Current.Response;  
       response.Clear();  
       response.ClearContent();  
       response.ClearHeaders();  
       response.Buffer = true;  
       response.AddHeader("Content-Disposition", "attachment;filename="+FileName);  
       byte[] data = req.DownloadData(Server.MapPath(strURL));  
       response.BinaryWrite(data);  
       response.End();  
     }  
     catch (Exception ex)  
     {  
     }  
   }