ExtAspNet下通过文档路径实现文档的下载

<ext:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" EnableAjax="false">//<span style="font-family: Arial, Helvetica, sans-serif;">EnableAjax="false"最重要了</span>

        </ext:Button>

 protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            string filepath = "E:\\123.xls";
            string filename = System.IO.Path.GetFileName(filepath);
            Response.Clear();
            Response.ClearHeaders();
            Response.Buffer = false;
            Response.ContentType = "application/octet-stream";
            //Response.ContentEncoding=System.Text.Encoding.GetEncoding("utf-8");
            Response.AddHeader("Content-Disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(filename, Encoding.UTF8));
            Response.WriteFile(filepath);
            Response.Flush();
            Response.End();
        }
        catch (Exception E)
        {
            //alert("没有找到您所要下载的数据!

"); } }


posted @   gccbuaa  阅读(180)  评论(0编辑  收藏  举报
编辑推荐:
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· 分享一个我遇到过的“量子力学”级别的BUG。
· Linux系列:如何调试 malloc 的底层源码
阅读排行:
· 对象命名为何需要避免'-er'和'-or'后缀
· JDK 24 发布,新特性解读!
· C# 中比较实用的关键字,基础高频面试题!
· .NET 10 Preview 2 增强了 Blazor 和.NET MAUI
· SQL Server如何跟踪自动统计信息更新?
点击右上角即可分享
微信分享提示