下载链接编写
<asp:LinkButton ID="lbBt" runat ="server" Text ="内务管理系统数据导入标准格式.xls" PostBackUrl ="DownLoad.aspx?FilePath=内务管理系统数据导入标准格式.xls"></asp:LinkButton>
在DownLoad.aspx中写入:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Inspur.Finix.Portal.Equipment.zcgl_zichantaizhang
{
    public partial class DownLoad : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["FilePath"] != null)
            {
                string filename = Server.MapPath("../docs/") + Request.QueryString["FilePath"].ToString();
                System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(System.IO.Path.GetFileName(filename)));
                System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel";// 指定返回的是一个不能被客户端读取的流,必须被下载 
                System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
                System.Web.HttpContext.Current.Response.WriteFile(filename); // 把文件流发送到客户端
                System.Web.HttpContext.Current.Response.Flush();
            }
        }
    }
}
                    
                
                
            
        
浙公网安备 33010602011771号