The fileupload in Asp.net Ajax and Asp.net 2.0 work together to create a new version.

Source: Internet
Author: User

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...

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.