1: protected void Button1_Click(object sender, EventArgs e) {
2: StartUpLoad();
3: }
4:
5: private void StartUpLoad() {
6: //get the file name of the posted image
7: string imgName = FileUpload1.FileName;
8: //sets the image path
9: string imgPath = "ImageStorage/" + imgName;
10: //get the size in bytes that
11:
12: int imgSize = FileUpload1.PostedFile.ContentLength;
13:
14: //validates the posted file before saving
15: if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "") {
16: // 10240 KB means 10MB, You can change the value based on your requirement
17: if (FileUpload1.PostedFile.ContentLength > 10240) {
18: Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('File is too big.')", true);
19: }
20: else {
21: //then save it to the Folder
22: FileUpload1.SaveAs(Server.MapPath(imgPath));
23: Image1.ImageUrl = "~/" + imgPath;
24: Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Image saved!')", true);
25: }
26:
27: }
28: }