欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【ASP.NET中通过对话框方式下载文件】,下面是详细的分享!
ASP.NET中通过对话框方式下载文件
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”; Response.End(); |
解决方法,再创建一个实例接收从资源文件或者数据库BLOB字段读入的图像内容。
解决方案代码:
| 以下为引用的内容: Bitmap bmp=this.GetGlobalResourceObject(“Resource”, ”_BitMap”) as Bitmap; Response.ContentType=“image/jpeg”; bmp.Dispose(); Response.End(); |
2、无法直接把PNG图像存入到输出流
原因:PNG是特殊的图片格式
解决方案代码:
| 以下为引用的内容: Bitmap bmp=this.GetGlobalResourceObject( “Resource”, “_BitMap”) as Bitmap; MemoryStream ms=new MemoryStream(); Response.ContentType=”image/png”; bmp.Dispose(); Response.End(); |
3、解决缓存问题
| 以下为引用的内容: Response.ContentType=”image/png”; MemoryStream stream1=new MemoryStream(); // DrawPie method return an Image Base.OnPreInit(e); |
以上所分享的是关于ASP.NET中通过对话框方式下载文件,下面是编辑为你推荐的有价值的用户互动:
相关问题:asp.net 我创建了一个Excel 工作簿,怎么显示下载...
答:1.如果你是在服务器上生成的Excel,可以直接Response.Redirect(“你生成的excel的地址”)。 2.如果你是字符串拼凑后的以html的形式转为excel /// /// 导出Excel /// /// /// protected void Button1_Click(object sender, EventArgs e) { Export("a... >>详细
相关问题:ASP.NET 实现文件下载(弹出打开保存文件对话框)
答:在点文件时,在点击事件里写 Response.Redirect("文件路径"); >>详细
相关问题:asp.net 点击“下载”弹出“下载文件”对话框,网页与...
答:#region private void FileDownLoad(string filename) /// /// 用户下载文件 /// /// 下载文件的路径 private void FileDownLoad(string filename) { string destFileName = filename; destFileName = Server.MapPath("./") + destFileName; des... >>详细
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
