Sunday, 1 January 2012

DownLoad File in Asp.net

Question:-Download File From website in Asp.net

Answer:-

Using System.IO;

string FileName="example.jpg";

System.IO.FileInfo  fi=new FileInfo(Server.MapPath(ResolveUrl("~/path/")+FileName));
Response.Clear();
Response.AddHeader("Content-Disposition","attachment;filename= \""+fi+"\"");
Response.AddHeader("Content-Length",fi.Length.ToString());
Response.ContentType="application/octet-stream";
Response.WriteFile(fi.FullName);
Response.End();

No comments:

Post a Comment