Html代码

 <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<a href="ImgDownloadHandler.ashx">下载</a>
<img src="http://10.1.18.59/CenterPointService/RainfallCenterTemp/20180319155952/20170601__20170930.png"
alt="RainfallCenter" id="RainfallCenter" />
</body>
</html>

C#一般处理程序代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.MobileControls;
using System.Drawing;
using System.IO;
using System.Net; namespace WebApplication1
{
/// <summary>
/// ImgDownloadHandler 的摘要说明
/// </summary>
public class ImgDownloadHandler : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
#region action 2 可以导出图片
Stream stream = null;
string UrlImg = "http://10.1.18.59/CenterPointService/RainfallCenterTemp/20180319155952/20170601__20170930.png";
WebClient webClient = new WebClient();
webClient.Credentials = CredentialCache.DefaultCredentials;
//以数组的形式下载指定文件
byte[] byteData = webClient.DownloadData(UrlImg);
stream = BytesToStream(byteData);
string fileName = "20170601__20170930.png";//客户端保存的文件名
context.Response.ContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
context.Response.BinaryWrite(byteData);
context.Response.Flush();
context.Response.End();
#endregion
}
/// <summary>
/// 将二进制转化为数据流
/// </summary>
/// <param name="bytes">二进制数组</param>
/// <returns></returns>
public Stream BytesToStream(byte[] bytes)
{
Stream stream = new MemoryStream(bytes);
return stream;
}
/// <summary>
/// 将流转化为二进制数组
/// </summary>
/// <param name="stream"></param>
/// <returns></returns>
public byte[] StreamToBytes(Stream stream)
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, , bytes.Length);
// 设置当前流的位置为流的开始
stream.Seek(, SeekOrigin.Begin);
return bytes;
} public bool IsReusable
{
get
{
return false;
}
}
}
}

最新文章

  1. ENode 2.6 架构与设计简介以及全新案例分享
  2. golang和vim-go安装配置
  3. 【Beta版本】冲刺-Day6
  4. 【HDU】4405 Aeroplane chess
  5. GIT(分布式版本控制系统)
  6. IOS开发-项目实战-点赞功能的实现
  7. udp内网穿透 两个内网互联
  8. android 源码目录介绍
  9. hdu1059 Dividing ——多重背包
  10. Redis实战
  11. C语言基础知识-循环结构
  12. WEB开发时Browser控件得到C:\fakepath\ 的解决方式
  13. denoising autoencoder
  14. CentOS上安装WordPress搭建博客平台
  15. Linux后门账户控制
  16. B树的查找、插入、删除(附源代码)
  17. 【论文:麦克风阵列增强】Speech Enhancement Based on the General Transfer Function GSC and Postfiltering
  18. java多线程知识点概述
  19. Linux常用命令(二)--文件目录命令
  20. SQL随记(三)

热门文章

  1. 分布式-信息方式-ActiveMQ支持的传输协议和配置
  2. C++入门经典-例5.5-空类型指针的使用
  3. oracle存储过程及sql优化-(一)
  4. 【python学习】字符串相关
  5. 取消 vue 的严格模式
  6. leetcode-easy-dynamic-53 Maximum Subarray
  7. 正则表达式中常用的模式修正符有i、g、m、s、x、e详解
  8. StringUtils.isBlank()检验String 类型的变量是否为空
  9. Emacs 浏览网页
  10. Android各种键盘挡住输入框解决办法