Extjs.net Button点击下载jpg图片

Posted ZGJ

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Extjs.net Button点击下载jpg图片相关的知识,希望对你有一定的参考价值。

<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图片的主要内容,如果未能解决你的问题,请参考以下文章

求html代码,点击按钮弹出层,再次点击关闭层?

IOS开发-UI学习-根据URL显示图片,下载图片的练习(button,textfield,image view,url,data)

CAD转换JPG图片格式

点击下载,下载图片

多线程下载服务端图片资源

tiff格式如何转换成jpg格式