查看: 13529|回复: 0
打印 上一主题 下一主题

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

[复制链接]
跳转到指定楼层
1#
发表于 2007-9-21 16:20:29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
台州网址导航
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);
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享分享 分享淘帖
台州维博网络(www.tzweb.com)专门运用PHP+MYSQL/ASP.NET+MSSQL技术开发网站门户平台系统等。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

网站推广
关于我们
  • 台州朗动科技(Tzweb.com)拥有多年开发网站平台系统门户手机客户端等业务的成功经验。主要从事:政企网站,系统平台,微信公众号,各类小程序,手机APP客户端,浙里办微应用,浙政钉微应用、主机域名、虚拟空间、后期维护等服务,满足不同企业公司的需求,是台州地区领先的网络技术服务商!

Hi,扫描关注我

Copyright © 2005-2026 站长论坛 All rights reserved

Powered by 站长论坛 with TZWEB Update Techonolgy Support

快速回复 返回顶部 返回列表