Asp. NET to download files through dialog box

Source: Internet
Author: User
Tags resource

1 to download or open the file by probing the dialog box

2 allow a specific application to open a file through a custom header

Method of Use: Response.TransmitFile ()

Routines:

以下是引用片段:
Response.ContentType=“image/jpeg”;
Response.AppendHeader(“Content-Disposition”,”attachment;filename=SailBig.jpg”);
Response.TransmitFile(Server.MapPath(“~/images/sailbig.jpg”));

流传送所使用的方法:Response.BinaryWrite()和Response.OutputStream()

Routines:

以下是引用片段:
Bitmapbmp=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);

Reference URL for the content Type (MIME type):

Http://www.w3.org/TR/html4/types.html (Overview)

http://www.iana.org/assignments/media-types/(Detailed list)

FAQ Solution:

1. Error occurred loading image from resource file or database blob field

Error content: A generic error occurred in GDI +

Code:

以下是引用片段:
Bitmapbmp=this.GetGlobalResourceObject(“Resource”,”_BitMap”)asBitmap;
Response.ContentType=”image/jpeg”;
bmp.Save(Response.OutputStream,ImageFormat.Jpeg);
Response.End();

Workaround, and then create an instance to receive the image content that is read from the resource file or from the Database Blob field.

Solution Code:

以下是引用片段:
  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();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.