码迷,mamicode.com
首页 > Web开发 > 详细

Extjs.net Button点击下载jpg图片

时间:2018-07-10 11:09:23      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:file   点击下载   extjs   headers   nts   click   pre   context   get   

<ext:Button ID="DownLoad" runat="server" Text="下载二维码" Width="120" Height="35"
    AutoPostBack="false">
    <DirectEvents>
        <Click OnEvent="DownLoad_Click">
        </Click>
    </DirectEvents>
</ext:Button>
protected void DownLoad_Click(object sender, DirectEventArgs e)
{
    WriteFile("/images/1.jpg");
}
public void WriteFile(string filePath)
{

    try
    {
        string _pre_path = filePath;
        filePath = Server.MapPath(filePath);
        if (File.Exists(filePath))
        {
            FileInfo info = new FileInfo(filePath);
            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("Content-Disposition", "attachment;filename=" + System.IO.Path.GetFileName(filePath));
            Response.AddHeader("Content-Length", info.Length.ToString());
            Response.AddHeader("Content-Transfer-Encoding", "binary");
            Response.ContentType = "application/octet-stream";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
            Response.WriteFile(info.FullName);
            Response.Flush();
            Response.End();

        }
    }
    catch (System.Threading.ThreadAbortException ex0) { }
    catch (Exception ex1)
    { }
    finally
    {
        HttpContext.Current.Response.Close();
    }
}

如果使用以上代码会报200错误,但是在Button上加一个就能正常运行,很莫名其妙,1.2版本。

<ext:FileUploadField ID="fileUpload" runat="server" ButtonOnly="true" EmptyText="上传LOGO"
    ButtonText="">
</ext:FileUploadField>
<ext:Button ID="DownLoad" runat="server" Text="下载二维码" Width="120" Height="35"
    AutoPostBack="false">
    <DirectEvents>
        <Click OnEvent="DownLoad_Click">
        </Click>
    </DirectEvents>
</ext:Button>

 

Extjs.net Button点击下载jpg图片

标签:file   点击下载   extjs   headers   nts   click   pre   context   get   

原文地址:https://www.cnblogs.com/zhaogaojian/p/9287127.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!