none
ASP.NET Web Forms FAQ: Bagaimana cara meng-upload file gambar? (Part 3)

    General discussion

  • if (type == "jpg" || type == "gif" || type == "bmp" || type == "JPG" || type == "GIF") 
                    { 
                        string ImagePath = "images/"; 
                        string sPath = Server.MapPath(ImagePath) + dataName + fileName; 
                        string imgPath = ImagePath + dataName + fileName; 
                        this.FileUpload1.PostedFile.SaveAs(sPath); 
                        this.ClientScript.RegisterStartupScript(this.GetType(),  
                              "Startup", "<script language='javascript'>alert('Success!');</script>"); 
                        this.Image1.ImageUrl = imgPath; 
                        this.btnSubmit.Enabled = false; 
                        this.btnSubmit.Text = "Success!"; 
                        this.btnSubmit.Enabled = true; 
     
                    } 
                    else 
                    { 
                        this.ClientScript.RegisterStartupScript(this.GetType(), "Startup",  
                              "<script language='javascript'>alert('File type is not right!');</script>"); 
                    } 
                } 
            } 
            else 
            { 
                this.ClientScript.RegisterStartupScript(this.GetType(), "Startup",  
                       "<script language='javascript'>alert('The uploaded file is not a image file!');</script>"); 
            } 
        } 
    }

     

    Thread terkait: http://forums.asp.net/p/1051895/2171502.aspx


    Agnes Sannie [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, August 26, 2011 5:48 AM
    Moderator