Author: Internet Prodigal Box (formerly known as littlehb) http://blog.9cbs.net/littlehb/ upload pictures, pictures 200100 pixels requirements, size is less than 2M, if the picture does not meet the requirements, can not upload, or upload pictures, upload After the picture is dynamically named by the system date, the path is reserved to the database.
private void Button1_Click (object sender, System.EventArgs e) {if (File1.PostedFile.ContentType.ToUpper () IndexOf ( "IMAGE")> -. 1) {System.Drawing.Image img = System.Drawing.Image.FromStream (File1.postedfile.inputstream); int width = img.width; int Height = img.height; if (width> 200 || Height> 100 || File1.postedFile.ContentLength> 1024 * 1024 * 2) {response.write ("Do not: width =" width.toString () "
Height =" height.toString () "
size =" (this.file1.postedfile.contentLength / 1024) .tostring ( "##, ## 0.00") "k");} else {string spath = server.mappath (system.datetime.now.tostring ("YYY-MM-DD HH-MM-SS") session.SessionID ".jpg"); this.file1.postedfile.saveas (spath); Response.write ("Save Success");}} else {response.write ("Please select a picture file!");}}