Site backstage all need to have the function of uploading pictures, the following example is the implementation of the picture upload. Disadvantage: The picture uploaded to this server, not suitable for a large number of picture upload
First, picture upload, code as follows: Xxx.aspx code as follows: <td class= "Style1" > <asp:fileupload id= "FileUpload1" runat= "server" /> &N Bsp <asp:button id= "Button1" runat= "server" text= "Upload general picture" onclick= "Button1_Click"/> </td> <TD class= "Style3" > & nbsp <asp:image id= "Image1" runat= "Server" height= "200px" width= "200px"/> &nbs P </td> Xxx.aspx.cs code as follows: protected void Button1_Click (object s Ender, EventArgs E) { for (int i = 0; i < Request . Files.count; i++) { Httppostedfile fi Le =Request.files[i]; if (file. ContentLength > 0) { if (file. Contenttype.contains ("image/")) { &NBS P using (System.Drawing.Image img = System.Drawing.Image.From Stream (file. InputStream) { & nbsp String FileName = System.IO.Path.GetFileName (file. FileName); string[] Splitfilename = Filename.split ('. '); &NBSP; String atterfilename = DateTime.Now.ToString ("YYYMMDDHHMMSS") + "." + splitfilename[1]; img Save (Server.MapPath ("/upload/" + atterfilename)); this. Image1.imageurl = "upload/" + atterfilename; & nbsp } else &NB Sp { & nbsp Response.Write (' <script>alert (' The file is not a picture format! ');</script> "); & nbsp } &NBSp else { &NB Sp Response.Write ("<script>alert (' Please select picture to upload ');</script>"); } } Second, add text watermark image upload, code as follows: Xxx.aspx code as follows: <td class= "Style1" > &nb Sp <asp:fileupload id= "FileUpload2" runat= "server"/> &N Bsp <asp:button id= "Button2" runat= "server" text= "Upload text picture" onclick= "button2_click"/ > </td> <TD>&NBSP ; <asp:image id= "Image2" runat= "Server" height= "200px" width= "200 PX "/> </td> Xxx.aspx.cs code as follows: protected void Button2_Click (object sender, EventArgs e) { for (int i = 0; i < reques T.files.count; i++) { Httppostedfile fi Le = Request.files[i]; if (file. ContentLength > 0) { if (file. Contenttype.contains ("image/")) { &NBS P using (System.Drawing.Image img = System.Drawing.Image.From Stream (file. InputStream) { using (Graphics g = Graphics.fromimag E (IMG)) { g.drawstring ("My Pictures", new Font ("XXFarEastFont-Arial", brushes.red, 0, 0); } & nbsp String FileName = System.IO.Path.GetFileName (file. FileName); string[] Splitfilename = Filename.split ('. '); string atterfilename = D AteTime.Now.ToString ("Yyymmddhhmmss") + "." + splitfilename[1];   img Save (Server.MapPath ("/upload/" + atterfilename)); this. Image2.imageurl = "upload/" + atterfilename; & nbsp } else &NB Sp { & nbsp Response.Write (' <script>alert (' The file is not a picture format! ');</script> "); & nbsp } else {  Response.Write ("<script>alert (' Please select the picture to upload") </ Script> "); } } Third, add picture watermark image upload, code as follows: Xxx.aspx Code as follows: <td class= "Style1" >&nbs P <asp:fileupload id= "FileUpload3" runat= "server"/> &N Bsp <asp:button id= "Button3" runat= "server" text= "Upload watermark Picture" onclick= "button3_ Click "/> </td> <td& gt; <asp:image id= "Image3" runat= "Server" height= "200px" Width= "200px"/> </td> Xxx.aspx.cs code is as follows: protected void BuTton3_click (object sender, EventArgs e) { for (int i = 0; i < Request.Files.Count; i++) { Httppostedfile fi Le = Request.files[i]; if (file. ContentLength > 0) { if (file. Contenttype.contains ("image/")) { &NBS P String fileName = file. FileName; using (System.Drawing.Image img = Syst Em. Drawing.Image.FromStream (file. InputStream) { using (system.drawing.i Mage Imgwater = System.Drawing.Image.FromFile (Server.MapPath ("/img/czlogo.jpg")) & nbsp { & nbsp using (Graphics g = Graphics.fromimage (img)) { & nbsp G.drawimage (imgwater, 0, 0); } & nbsp string[] Splitfilename = Filename.split ('. '); string Att Erfilename = DateTime.Now.ToString ("YYYMMDDHHMMSS") + "." + splitfilename[1]; img Save (Server.MapPath ("/upload/" + atterfilename)); this. Image3.imageurl = "upload/" + atterfilename; } & nbsp & nbsp } else &NB Sp { &NBsp Response.Write (' <script>alert (' This file is not a picture format! ');</script> "); & nbsp } else {& nbsp Response.Write ("<script>alert (' Please select the picture to upload") </ Script> "); } } IV, upload image condensed map, code as follows: Xxx.aspx code as follows: <td class= "Style1" > <asp:fileupload id= "FileUpload4" runat= "server"/> &N Bsp <asp:button id= "Button4" runat= "server" text= "upload condensed picture" onclick= "Button4_Click"/> </td> <td> <asp : Image id= "Image4" runat= "Server" height= "200px" width= "200px"/> </ td> Xxx.aspx.cs code is as follows: protected void Button4_Click (object sender, EventArgs e) { for (int i = 0; i < Request.Files.Count i++) { Httppostedfile file = Request.files[i]; &nb Sp if (file. ContentLength > 0) { if (file. Contenttype.contains ("image/")) { &NBSP ; &NBSp using (System.Drawing.Image img = System.Drawing.Image.FromStream (file. InputStream) { & nbsp using (System.Drawing.Image imgthumb = new Bitmap (20 0)) { using (Graphics g = Gra Phics. FromImage (Imgthumb)) &NB Sp { & nbsp G.drawimage (IMG, new Rectangle (0, 0, Imgthumb.width, imgthumb.height), new Rectangle (0, 0, IMG). Width, IMG. Height), GraphicsUnit.Pixel); { & nbsp String fileName = file. FileName; string[] S Plitfilename = Filename.split ('. '); string Att Erfilename = DateTime.Now.ToString ("YYYMMDDHHMMSS") + "." + splitfilename[1]; img Save (Server.MapPath ("/upload/" + atterfilename)); this. Image4.imageurl = "upload/" + atterfilename; { { } Else { &N Bsp Response.Write (' <script>alert (' This file is not a picture format! ');</script> "); & nbsp } else {& nbsp Response.Write ("<script>alert (' Please select the picture to upload") </ Script> "); }   }