예제 #1
0
        protected void btnUploadPhoto_Click(object sender, EventArgs e)
        {
            //Checking if user uploads jpeg file

            string photoURL = "images/placeholder.jpg";

            if (fupAddPhoto.HasFile)
            {
                try
                {
                    if (fupAddPhoto.PostedFile.ContentLength < 512000)
                    {
                        //Need to think of another photo name because we can't use email address
                        string fileName  = Session["Email"].ToString();
                        string extension = Path.GetExtension(fupAddPhoto.PostedFile.FileName);
                        fupAddPhoto.SaveAs(Server.MapPath("~/Storage//") + fileName + fupAddPhoto.PostedFile.FileName + extension);
                        lblMessage.Text = "Photo uploaded!";
                        photoURL        = "/Storage/" + fileName + extension;
                    }
                    else
                    {
                        lblMessage.Text = "The file has to be less than 500 kb!";
                    }
                }
                catch (Exception ex)
                {
                    lblMessage.Text = "The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
            if (procedures.AddPhoto(Session["Email"].ToString(), photoURL, txtPhotoDescription.Text, Convert.ToInt32(Session["VerificationToken"])) == true)
            {
                lblMessage.Text = "Photo successfully updated.";
            }
            else
            {
                lblMessage.Text = "Unable to add photo.";
            }
            //Validation for changed in user profile
            //Stored Procedures to update the database with new user information
        }