logo 广告
Loading...
 导航 所在位置:论坛首页 -> ┈┋电脑网络┋┈ -> Asp/Asp.Net教程 -> ASP.NET中通过对话框方式下载文件
回复
标题:ASP.NET中通过对话框方式下载文件收藏 编辑 删除 楼主 | 上一篇 下一篇
年少轻狂
头像
等级:社区游侠
权限:普通用户
积分:37
金钱:3647
声望:64
经验:64
发帖数:861
注册:2007年10月26日
资料 短消息2008-4-8 10:50:25

ASP.NET中通过对话框方式下载文件

1 通过探出对话框提示文件下载或打开

2 通过自定义Header让特定的应用程序打开文件 

使用的方法:Response.TransmitFile() 

例程:

Response.ContentType = “image/jpeg”;
Response.AppendHeader(“Content-Disposition”,”attachment; filename=SailBig.jpg”);
Response.TransmitFile( Server.MapPath(“~/images/sailbig.jpg”) ); 

流传送所使用的方法:

Response.BinaryWrite()和Response.OutputStream()

例程: 

Bitmap bmp = wwWebUtils.CornerImage(backcolor, color, c, Radius, Height, Width);
Response.ContentType = “image/jpeg”;
Response.AppendHeader(“Content-Disposition”,”attenment; filename=LeftCorner.jpg”);
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);

关于Content Type(MIME Type)的参考URL:

http://www.w3.org/TR/html4/types.html (概述) 

http://www.iana.org/assignments/media-types/ (详细列表) 

常见问题解决方案:

1、当从资源文件或者数据库BLOB字段载入图像出现错误

错误内容:A generic error occurred in GDI+

代码:

Bitmap bmp = this.GetGlobalResourceObject(“Resource”,”_BitMap”) as Bitmap;
Response.ContentType=”image/jpeg”;
bmp.Save(Response.OutputStream, ImageFormat.Jpeg); 
Response.End();

解决方法,再创建一个实例接收从资源文件或者数据库BLOB字段读入的图像内容。

解决方案代码: 

Bitmap bmp = this.GetGlobalResourceObject(“Resource”, ”_BitMap”) as Bitmap;
Bitmap temp = new Bitmap(bmp); 
Response.ContentType = “image/jpeg”;
Temp.Save(Response.OutputStream, ImageFormat.Jpeg);
bmp.Dispose();
temp.Dispose(); 
Response.End();
 
2、无法直接把PNG图像存入到输出流

原因:PNG是特殊的图片格式

解决方案代码:

Bitmap bmp = this.GetGlobalResourceObject( “Resource”, “_BitMap”) as Bitmap;
Bitmap temp = new Bitmap(bmp); 
MemoryStream ms = new MemoryStream();
Response.ContentType=”image/png”;
temp.Save(ms, System.Drawing.Imaging, ImageFormat.Png);
Ms.WriteTo(Response.OutputStream);
bmp.Dispose();
temp.Dispose();
Response.End();

3、解决缓存问题

Response.ContentType=”image/png”;
Response.Buffer = false;
Response.Clear(); 
MemoryStream stream1 = new MemoryStream();
// DrawPie method return an Image
This.DrawPie(table1).Save(stream1,ImageFormat.Png);
Response.BinaryWrite(stream1.ToArray()); 
Base.OnPreInit(e);

签名

2008-4-8 10:50:25 顶部
第1页 共页 共0个回复     <<    >>    
 快速回复
  • 支持UBB,HTML标签

  • 高级回复

  • 操作选项:评分 加精 解精 奖惩 设专题 设公告 解公告 固顶 总固顶 解固顶 结帖 解结帖 锁帖 解锁 移帖 删帖
      首页 | 购买指南 | 虚拟主机 | 特色介绍 | 下载中心 | 支付方式
    Copyright 2004-2008 BBSGood.com Powered By: BBSGood.Speed Version 5.0
      咨询电话:0575-85513832、0575-85513825(传真)、7*24小时咨询服务:13606552007 不良信息举报中心 浙ICP备05029817号
      业务QQ:38958768、客服QQ1:415896239、客服QQ2:343896043、MSN:jccsxx@hotmail.com