Asp. NET to download files through dialog box

Source: Internet
Author: User
Tags resource

Asp. NET to download files through dialog box

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"));

The method used to circulate:

Response.BinaryWrite () and Response.outputstream ()

Routines:

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);

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:

Bitmap bmp = this. GetGlobalResourceObject ("Resource", "_bitmap") as BitMap;
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 ();

2, not directly to the PNG image into the output stream

Reason: PNG is a special picture format

Solution Code:

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, solve the cache problem

Response.contenttype= "Image/png";
Response.Buffer = false;
Response.Clear ();
MemoryStream stream1 = new MemoryStream ();
Drawpie method return a Image
This.drawpie (table1). Save (stream1,imageformat.png);
Response.BinaryWrite (stream1. ToArray ());
Base.onpreinit (e);



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.