html5中文学习网

您的位置: 首页 > 网络编程 > ASP.NET » 正文

ASP.NET中通过对话框方式下载文件_.NET教程_编程技术

[ ] 已经帮助:人解决问题

ASP.NET中通过对话框方式下载文件gxHHTML5中文学习网 - HTML5先行者学习网

1 通过探出对话框提示文件下载或打开 gxHHTML5中文学习网 - HTML5先行者学习网

2 通过自定义Header让特定的应用程序打开文件  gxHHTML5中文学习网 - HTML5先行者学习网

使用的方法:Response.TransmitFile()  gxHHTML5中文学习网 - HTML5先行者学习网

例程: gxHHTML5中文学习网 - HTML5先行者学习网

Response.ContentType = “image/jpeg”;
Response.AppendHeader(“Content-Disposition”,”attachment; filename=SailBig.jpg”);
Response.TransmitFile( Server.MapPath(“~/images/sailbig.jpg”) );  gxHHTML5中文学习网 - HTML5先行者学习网

流传送所使用的方法:gxHHTML5中文学习网 - HTML5先行者学习网

Response.BinaryWrite()和Response.OutputStream() gxHHTML5中文学习网 - HTML5先行者学习网

例程:  gxHHTML5中文学习网 - HTML5先行者学习网

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); gxHHTML5中文学习网 - HTML5先行者学习网

关于Content Type(MIME Type)的参考URL: gxHHTML5中文学习网 - HTML5先行者学习网

http://www.w3.org/TR/html4/types.html (概述)  gxHHTML5中文学习网 - HTML5先行者学习网

http://www.iana.org/assignments/media-types/ (详细列表)  gxHHTML5中文学习网 - HTML5先行者学习网

常见问题解决方案: gxHHTML5中文学习网 - HTML5先行者学习网

1、当从资源文件或者数据库BLOB字段载入图像出现错误 gxHHTML5中文学习网 - HTML5先行者学习网

错误内容:A generic error occurred in GDI+ gxHHTML5中文学习网 - HTML5先行者学习网

代码: gxHHTML5中文学习网 - HTML5先行者学习网

Bitmap bmp = this.GetGlobalResourceObject(“Resource”,”_BitMap”) as Bitmap;
Response.ContentType=”image/jpeg”;
bmp.Save(Response.OutputStream, ImageFormat.Jpeg); 
Response.End();gxHHTML5中文学习网 - HTML5先行者学习网

解决方法,再创建一个实例接收从资源文件或者数据库BLOB字段读入的图像内容。 gxHHTML5中文学习网 - HTML5先行者学习网

解决方案代码:  gxHHTML5中文学习网 - HTML5先行者学习网

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图像存入到输出流 gxHHTML5中文学习网 - HTML5先行者学习网

原因:PNG是特殊的图片格式 gxHHTML5中文学习网 - HTML5先行者学习网

解决方案代码: gxHHTML5中文学习网 - HTML5先行者学习网

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();gxHHTML5中文学习网 - HTML5先行者学习网

3、解决缓存问题 gxHHTML5中文学习网 - HTML5先行者学习网

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); gxHHTML5中文学习网 - HTML5先行者学习网

gxHHTML5中文学习网 - HTML5先行者学习网
gxHHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助