protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("download.aspx?file=~/images/aa.txt"); }
protected void Page_Load(object sender, EventArgs e) { string strRequest =(string) Request.QueryString["file"]; if (!string.IsNullOrEmpty(strRequest)) { string path = Server.MapPath(strRequest); System.IO.FileInfo file = new System.IO.FileInfo(path); if (file.Exists) { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name); Response.AddHeader("Content-Length", file.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.WriteFile(file.FullName); Response.End(); } else { Response.Write("This file does not exist."); } } else { Response.Write("Please provide a file to download."); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)