Saturday, 10 January 2015

File Download From Asp.net C#

 string strURL = “URL”;
 string FileName = string.Empty;

 FileName = strURL.Substring(strURL.LastIndexOf('/') + 1);

 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();

No comments:

Post a Comment