The. aspx code is as follows:
<%@ page title= "" Language= "C #" masterpagefile= "~/sample_code/amst_sample.master" autoeventwireup= "true" CodeFile = "S6_downloadLink.aspx.cs" inherits= "Sample_code_s8_downloadlink"%><asp:content id= "Content1" Contentplaceholderid= "Cph_head" runat= "Server" ></asp:content><asp:content id= "Content2" Contentplaceholderid= "Cph_memo" runat= "Server" > <ul> <li> Normal hyperlinks <a> sometimes not enough to meet the needs of the download, but the browser opens the text directly Pieces </li> </ul></asp:content><asp:content id= "Content3" contentplaceholderid= "Cph_main" Runat= " Server > <p> Normal hyperlink link a picture file [direct Open]: <a href= ". /imgs/img1.jpg "> <a href=". /imgs/img1.jpg "/> </a></p> <p> normal hyperlink link a rar file [download]: <a href=". /imgs/temp.rar "> <a href=". /imgs/temp.rar "/> </a> </p> <p> Normal hyperlink to a WAV file [the plug-in or run environment is different and decided to open or download]: <a href=". /imgs/music1.wav "> <a href=". /imgs/music1.wav "/> ≪/a></p> <p> Pictures <a href= "with hyperlinks with [download] Properties". /imgs/img1.jpg "download=" myimg.jpg "> Picture download </a> </p> <p style=" FONT-SIZE:16PX; color:red; " > completely does not expose the download of the target file LinkButton <asp:linkbutton id= "LinkButton1" runat= "Server" onclick= "LinkButton1_Click" > Picture file Download </asp:LinkButton> </p></asp:Content>
The. Aspx.cs code is as follows:
Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.UI;using System.web.ui.webcontrols;public partial class sample_code_s8_downloadlink:system.web.ui.page{ protected void Page_Load (object sender, EventArgs e) { } protected void LinkButton1_Click (object sender, EventArgs e) { String fileName = "Tempimg.jpg"; String filePath = Server.MapPath ("~/imgs/img3.jpg"); Response.Clear (); Response.Buffer = true; Response.AddHeader ("Content-disposition", "attachment;filename=" + filename); Response.ContentType = "Application/unknow"; Response.TransmitFile (FilePath); Response.End (); }}
The results are as follows:
ASP. net File download