Images are used when an information management platform is created, just like an uploaded
ASP. NET Ajax is useful
I tried to create
Not good
Custom User Control File picupload. ascx
1 <% @ Control Language = "C #" autoeventwireup = "true" inherits = "admin_picupload, app_web_mboefw14" %>
2 <asp: Image id = "ep_image" runat = "server" Height = "160px" imageurl = '<% # BIND ("ep_pic") %>'
3 width = "314px"/>
4 <br/>
5 <asp: fileupload id = "fileupload1" runat = "server"/>
6 <asp: button id = "button1" runat = "server" onclick = "button#click" text = "Upload"/>
Custom User Control File picupload. ascx. CS
1 using system;
2 using system. Data;
3 using system. configuration;
4 using system. collections;
5 using system. Web;
6 using system. Web. Security;
7 using system. Web. UI;
8 using system. Web. UI. webcontrols;
9 using system. Web. UI. webcontrols. webparts;
10 using system. Web. UI. htmlcontrols;
11
12 public partial class admin_picupload: system. Web. UI. usercontrol
13 {
14 protected void page_load (Object sender, eventargs E)
15 {
16
17}
18 protected void button#click (Object sender, eventargs E)
19 {
20 bool fileok = false;
21 // obtain the absolute path of the root file
22 string Path = server. mappath ("~ /Upload /");
23 // if a file is uploaded, the file format is determined.
24 fileupload Fu = fileupload1;
25 if (Fu. hasfile)
26 {
27 string fileextension = system. Io. Path. getextension (Fu. filename). tolower ();
28 string [] allowedextensions = {". GIF", ". jpg", ". PNG", ". BMP ",};
29 for (INT I = 0; I <allowedextensions. length; I ++)
30 {
31 if (fileextension = allowedextensions [I])
32 {
33 fileok = true;
34}
35}
36}
37 // call the saveas method to upload files
38 If (fileok)
39 {
40 try
41 {
42 fileupload1.saveas (path + system. datetime. Now. tostring ("yyyymmddhhmmss") + Fu. filename );
43 ep_image.imageurl = "../upload/" + system. datetime. Now. tostring ("yyyymmddhhmmss") + Fu. filename;
44 button1.text = "Upload successful ";
45}
46 finally
47 {
48}
49}
50 else
51 {
52 button1.text = "Upload Failed, format not allowed ";
53}
54}
55}
56
Step by step...