Saturday, October 23, 2010

How to Download File from asp.net

string st, doctitle;
doctitle = e.CommandArgument.ToString();
st = Server.MapPath("../documents") + "//" + doctitle;
FileInfo f = new FileInfo(st);
if (f.Exists == true)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=" + f.Name);
Response.AddHeader("content.length", f.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(f.FullName);
Response.End();
}

No comments:

Post a Comment