protected void btn_download_Click(object sender, EventArgs e) { string filename = "SherAcc.exe"; if (filename != "") { string path = Server.MapPath(filename); System.IO.FileInfo file = new System.IO.FileInfo(path); if (file.Exists) { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment; SheraAcc=" + 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."); } } }
The output : downloading the page
note : exe file place in same location of the project no additional folder used