protected void Button2_Click(object sender, EventArgs e) { StartUpLoad(); } private void StartUpLoad() { //get the file name of the posted image string imgName = FileUpload1.FileName; //sets the image path string imgPath = "Images/" + imgName; //get the size in bytes that int imgSize = FileUpload1.PostedFile.ContentLength; //validates the posted file before saving if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "") { // 10240 KB means 10MB, You can change the value based on your requirement if (FileUpload1.PostedFile.ContentLength > 10240) { Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('File is too big.')", true); } else { //then save it to the Folder FileUpload1.SaveAs(Server.MapPath(imgPath)); Image1.ImageUrl = "~/images/" + imgPath; Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Image saved!')", true); } } }
Image1.ImageUrl = "~/images/" + imgName;
Image1.ImageUrl = "~/images/" + imgPath;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)