首页| JavaScript| HTML/CSS| Matlab| PHP| Python| Java| C/C++/VC++| C#| ASP| 其他|
购买积分 购买会员 激活码充值

您现在的位置是:虫虫源码 > C# > C# 下载图片示例

C# 下载图片示例

  • 资源大小:1.38KB
  • 上传时间:2021-07-26
  • 下载次数:0次
  • 浏览次数:1次
  • 资源积分:1积分
  • 标      签: C#语言基础

资 源 简 介

<%@ WebHandler Language="C#" Class="DownImg" %>using System;using System.Web;public class DownImg : IHttpHandler { //图片下载功能 public void ProcessRequest(HttpContext context) { System.Net.WebResponse response = null; System.IO.Stream stream = null; string path = context.Request.Url.Query.Split(new string[] { "coverimg=" }, StringSplitOptions.RemoveEmptyEntries)[1]; System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(path); response = request.GetResponse(); stream = response.GetResponseStream(); System.IO.MemoryStream memStream = Txooo.Mobile.HttpTools.CloneStream(stream); byte[] bytes = new byte[memStream.Length]; memStream.Read(bytes, 0, bytes.Length); // 设置当前流的位置为流的开始 memStream.Seek(0, System.IO.SeekOrigin.Begin); context.Response.ContentType = "application/octet-stream"; //通知浏览器下载文件而不是打开 string fileName = DateTime.Now.Ticks.ToString() ".jpg"; context.Response.AddHeader("Content-Disposition", "attachment; filename=" fileName); context.Response.BinaryWrite(bytes); context.Response.Flush(); } public bool IsReusable { get { return false; } }}

相 关 资 源

您 可 能 感 兴 趣 的

同 类 别 推 荐

VIP VIP
0.181151s