您现在的位置: 网页制作教程网 >> 网络编程 >> Asp.net 教程 >> ASP.NET 实例教程 >> 文章正文

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

作者:天极Yesk…

来源:天极Yesky

热度:

2007-6-21 9:55:58

  解决方法,再创建一个实例接收从资源文件或者数据库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);

  可以参考的资料:

  Build Smarter ASP.NET File Downloading Into Your Web Applications

  http://msdn.microsoft.com/msdnmag/issues/06/09/webdownloads/default.aspx

  How to: Download file from ASP.Net 2.0 Page

  http://geekswithblogs.net/rachit/archive/2007/04/20/How-to-ASP.Net-File-Download.aspx

上一页  [1] [2] 

我来说两句:

1分 2分 3分 4分 5分
姓名: *


* 请各位网友遵纪守法并注意语言文明。
网站简介 | 联系方式 | 意见建议 | 版权说明
Copyright © 2007 All rights reserved
滇ICP备06006992号