首页 > 代码库 > asp.net文件下载
asp.net文件下载
.aspx代码如下:
<%@ 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>普通的超链接 <a>有时无法满足下载的需求,而是用浏览器直接打开了文件</li> </ul> </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="CPH_MAIN" Runat="Server"> <p>普通超链接链接一个图片文件[直接打开]: <a href=http://www.mamicode.com/"../imgs/img1.jpg">>
.aspx.cs代码如下: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(); } }
运行效果如下:
asp.net文件下载
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。