分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

Extjs.net Button点击下载jpg图片

发布时间:2023-09-06 02:03责任编辑:林大明关键词:js
<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图片

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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved