一个以电子商务为主的信息资讯门户网站——165163.com
网站首页 | 信息资讯 | 网上商城 | 企业黄页 | 人才市场 | 供求信息 | 房产交易 | 二手市场
消费e店 | 时尚生活 | 在线影院 | flash动漫 | 笑话频道 | 真情交友 | 电子相册 | 博客日志
您所在的位置:东阳在线 > > 电脑网络 > 网页编程 浏览正文
ASP.NET中通过对话框方式下载文件
165163.com  发布:2008-3-16 15:22:36  来自:转载  浏览:

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); Chinaz.com

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(); Chinaz.com

Response.End();

[中国站长站]

3、解决缓存问题

以下为引用的内容:

Response.ContentType=”image/png”;
Response.Buffer = false;
Response.Clear();

 

MemoryStream stream1 = new MemoryStream(); Chinaz.com

// DrawPie method return an Image
This.DrawPie(table1).Save(stream1,ImageFormat.Png);
Response.BinaryWrite(stream1.ToArray());

Base.OnPreInit(e);

(编辑:) 留言评论】【在线投稿】【打印网页】【关闭窗口】【↑顶部
  + 相关信息咨讯
 ·关于ASP.NET在IIS一些问题的经验总结
 ·ADSL故障排除技巧
 ·如何选择宽带路由器
 ·UUSee网络电视2007 4.4.1214.18
 ·金山清理专家 2.3贺岁版
版权与免责声明:
1.凡本网注明来源为“东阳在线 ”的所有作品,包括文字与图片,未经本网授权不得转载。违反上述声明者,本网将依法追究法律责任。
2. 凡注明"来源:xxx(非本站)"的作品,均转载自其它媒体,本网转载的目的在于传播更多信息,此类稿件并不代表本网观点,本网不承担此类稿件侵权行为的直接责任及连带责任。
3. 如因作品内容、版权等需要同本网联系的,请在作品在本网发表之日起30日内联,否则视为放弃相关权利