protected void Button2_Click1(object sender, EventArgs e) { StartUpLoad(); } private void StartUpLoad() { //get the file name of the posted image string username = (string)(Session["UserAuthentication"]); string imgName = username; //sets the image path string imgPath = "Images/gallery/adil/" + 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 > 1024000) { 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 = username + imgPath; Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Image saved!')", true); } } }
<asp:Image ID="Image1" runat="server" ImageUrl="~/images/gallery/adil/dafult.jpg" Height="379px" Width="614px" />
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)