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