Step 1: Drop Link button on aspx page
Step 2: on the cs file write the following code:
protected void LinkButton1_Click(object sender, EventArgs e)
{
string fname="Your File Name";
string filepath = Server.MapPath("~//ZipFiles//" + fname);
FileInfo info = new FileInfo(filepath);
if (info.Exists == true)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + info.Name);
Response.AddHeader("Content-Length", info.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(info.FullName);
Response.End();
}
}
Step 2: on the cs file write the following code:
protected void LinkButton1_Click(object sender, EventArgs e)
{
string fname="Your File Name";
string filepath = Server.MapPath("~//ZipFiles//" + fname);
FileInfo info = new FileInfo(filepath);
if (info.Exists == true)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + info.Name);
Response.AddHeader("Content-Length", info.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(info.FullName);
Response.End();
}
}
No comments:
Post a Comment