/// <summary> /// Uploads a posted image to the candidate photo repository for the current candidate. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">An <see cref="EventArgs"/> object that contains the event data.</param> protected void UploadPhoto(object sender, EventArgs e) { if (Page.IsValid && this.IsPostBack) { // upload image try { if (_photoUpload.HasFile) { try { using (Image i = Image.FromStream(_photoUpload.FileContent, true, true)) { if (_photoUpload.FileContent.Length <= MaxPhotoFileSizeMB * BytesPerMegabyte) { string photoPath = ProfilePhotoHandler.GetPhotoFilePath(CPProfile.Cid); if (File.Exists(photoPath) && !string.IsNullOrEmpty(CPProfile.Cid)) { File.Delete(photoPath); } if ((i.Height > MaxPhotoHeight) || (i.Width > MaxPhotoWidth)) { using (Image t = MakeThumbnailFrom(i)) { t.Save(photoPath); } } else { i.Save(photoPath); } i.Dispose(); ShowGreeting(); } else { // when file is too big SetError(string.Format("The file provided exceeds the maximum acceptable image size of {0} MB. Please try uploading a smaller file.", MaxPhotoFileSizeMB)); } } } catch (ArgumentException) { // when file is valid but not an image SetError("The file provided is not a supported image. Please try uploading a BMP, GIF, JPG, TIF, or PNG file."); } } else { // when no file was supplied SetError("Please first browse to an image for uploading."); } } catch (ArgumentException) { // when an invalid path was supplied SetError("The file specified could not be found. Please try browsing to the file again."); } } }
public void GetPhotoFilePathTest() { string cid = string.Empty; // TODO: Initialize to an appropriate value string expected = string.Empty; // TODO: Initialize to an appropriate value string actual; actual = ProfilePhotoHandler.GetPhotoFilePath(cid); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
/// <summary> /// Deletes the current user-supplied photo on file for the candidate, if available. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">An <see cref="EventArgs"/> object that contains the event data.</param> protected void DeletePhoto(object sender, EventArgs e) { string photoPath = ProfilePhotoHandler.GetPhotoFilePath(CPProfile.Cid); if (File.Exists(photoPath)) { File.Delete(photoPath); } ShowGreeting(); _updatePanel.Update(); }