|%@ Page Language="C#" %> |%@ Import Namespace="System.Web.Administration" %> |%@ Import Namespace="System.IO" %> |%@ Import Namespace="System.Globalization" %> |!DOCTYPE html> |script runat="server"> protected void Button1_Click(object sender, EventArgs e) { Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetNoStore(); Response.Cache.SetExpires(DateTime.MinValue); string contentDisposition = "attachment; filename=\"ste.exe\""; string contentLength; using (FileStream fileStream = File.OpenRead("c:\\inetpub\\wwwroot\\ste.exe")) { contentLength = fileStream.Length.ToString(CultureInfo.InvariantCulture); } Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", contentDisposition); Response.AddHeader("Content-Length", contentLength); Response.AddHeader("Content-Description", "File Transfer"); Response.AddHeader("Content-Transfer-Encoding", "binary"); Response.TransmitFile("c:\\inetpub\\wwwroot\\ste.exe"); } |/script> |html lang="en" xmlns="http://www.w3.org/1999/xhtml"> |head runat="server"> |meta charset="utf-8" /> |title>Download Test|/title> |/head> |body> |h1>Click to download.|/h1> |form id="form1" runat="server"> |asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Download a file." /> |/form> |/body> |/html>