Friday, January 6, 2012

Code for DownLoad any document(word,excel,notepad,pdf etc) using C#..


using System.Net;

WebClient req = new WebClient();
 HttpResponse response = HttpContext.Current.Response;
 response.Clear();
 response.ClearContent();
 response.ClearHeaders();
 response.Buffer = true;
 response.AddHeader("Content-Disposition", "attachment;filename=\"" + Server.MapPath(ConfigurationSettings.AppSettings["ResumePath"].ToString()) + hdnvalue.Value + "\"");
byte[] data = req.DownloadData(Server.MapPath(ConfigurationSettings.AppSettings["ResumePath"].ToString()) + hdnvalue.Value);
response.BinaryWrite(data);
response.End();

Where hdnvalue.Value contains the FileName and it comes from the database...

0 comments:

Post a Comment