ASP. FileUpload control implements picture upload with preview display

Source: Internet
Author: User

Single image upload--"select" + "Upload",. NET default mode:

1. Principle of implementation:With the default use of the FileUpload control, the Select button selects the picture, then clicks the Upload button to complete the upload, and loads the uploaded picture in the Click event of the Upload button. 2. Key code:     Page code:
1<asp:fileupload id="FileUpload"runat="Server"/>2<asp:button id="Btnup"runat="Server"onclick="Btnup_click"text="Upload"/>3<asp:label id="labmsg"runat="Server"></asp:Label>4"img"runat="Server"Src=""/>
    Background code:  
1  /// <summary>2         ///Upload a single image--There are "select" + "Upload" two buttons3         /// </summary>4         /// <param name= "Sender" ></param>5         /// <param name= "E" ></param>6         protected voidBtnup_click (Objectsender, EventArgs e)7         {8             if(Fileupload.hasfile)9             {Ten                 stringSavepath = Server.MapPath ("~/upload/");//specify the path to save the uploaded file on the server One                 //Check that the physical path exists on the server and create if it does not exist A                 if(!System.IO.Directory.Exists (savepath)) -                 { - System.IO.Directory.CreateDirectory (savepath); the                 } -Savepath = Savepath +"\\"+Fileupload.filename; - Fileupload.saveas (savepath); -Labmsg.text =string. Format ("<a href= ' upload/{0} ' >upload/{0}</a>", fileupload.filename); +                  This. img. SRC ="upload/"+Fileupload.filename; -             } +             Else A             { atLabmsg.text ="you have not yet chosen to upload the file!"; -             } -}

ASP. FileUpload control implements picture upload with preview display

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.