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]