FileUpload uploading Files--[asp.net]

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.Security;namespacewebapplication1{ Public Partial classImport:System.Web.UI.Page {protected voidPage_Load (Objectsender, EventArgs e) {        }        protected voidButton2_Click (Objectsender, EventArgs e) {            //get the name of the uploaded file            stringName =Fileupload1.filename; //get the size of an uploaded file            stringSize =FileUpload1.PostedFile.ContentLength.ToString (); //gets the MIME content type of the file that has been uploaded            stringType =FileUpload1.PostedFile.ContentType; //get the file suffix name            stringtype2 = name. Substring (name. LastIndexOf (".") +1); //get the actual path to the file upload            stringIpath = Server.MapPath ("~/app_data/") +"\\"+name; //get the actual path to the file upload            stringFpath = Server.MapPath ("~/app_data/") +"\\"+name;//-----------Modify the place, the original is used "Upfile" "upimg" Get not//the virtual path to the database is written to            stringWpath ="upimg\\"+name; //determine the format of a file            if(Type2 = ="jpg"|| Type2 = ="gif"|| Type2 = ="BMP"|| Type2 = ="PNG")            {                //Save the file to the pathFileupload1.saveas (Ipath); //let the picture Show.Image1.imageurl =Wpath; Label1.Text="the file name you sent is:"+ name +"<br> File size is:"+ Size +"bytes <br> file type is:"+ Type +"the <br> suffix name is:"+ type2 +"<br> The actual path is:"+ Ipath +"the <br> virtual path is:"+Wpath; }            Else            {                //hide a pictureImage1.visible =false;                Fileupload1.saveas (Fpath); Label1.Text="the file name you sent is:"+ name +"<br> File size is:"+ Size +"bytes <br> file type is:"+ Type +"the <br> suffix name is:"+ type2 +"<br> The actual path is:"+ Ipath +"the <br> virtual path is:"+Wpath; }        }           }}

Page:

Sorry: Pictures of wood show out, but still satisfied with it, give yourself 80 points. Keep working on it. Uploading this is very common and will certainly be learned in the future.

FileUpload uploading Files--[asp.net]

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.