/// <summary> /// Handles the Click event of the btnUpload control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void btnUpload_Click(object sender, EventArgs e) { try { HttpPostedFile file = fuFile.PostedFile; fuFile.Dispose(); if (!IsValidFileType(Path.GetExtension(file.FileName))) { throw new ArgumentOutOfRangeException("file", "File is not of valid type."); } if(file.ContentLength > 0) { FileWriter fileWriter = new FileWriter(); string finalPath = HttpContext.Current.Server.MapPath(path) + fuFile.FileName; fileWriter.Write(finalPath, file.InputStream); if (SiteSettings.GenerateThumbs) { ImageProcess.ResizeAndSave(fuFile.FileContent, fuFile.FileName, HttpContext.Current.Server.MapPath(PRODUCT_IMAGE_THUMB_PATH), SiteSettings.ThumbSmallWidth, SiteSettings.ThumbSmallHeight); } LoadImageList(); Master.MessageCenter.DisplaySuccessMessage(LocalizationUtility.GetText("lblImageSaved")); } } catch(Exception ex) { Logger.Error(typeof(imageselector).Name + ".btnUpload_Click", ex); Master.MessageCenter.DisplayCriticalMessage(ex.Message); } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { try { HttpPostedFile file = fuFile.PostedFile; if (file.ContentLength > 0) { FileWriter fileWriter = new FileWriter(); string finalPath = HttpContext.Current.Server.MapPath(DOWNLOAD_PATH) + fuFile.FileName; fileWriter.Write(finalPath, file.InputStream); } Download artifact = null; if (!string.IsNullOrEmpty(lblDownloadId.Text)) { artifact = new Download(lblDownloadId.Text.Trim()); } else { artifact = new Download(); } artifact.DownloadFile = (file.ContentLength > 0) ? DOWNLOAD_PATH + fuFile.FileName : artifact.DownloadFile; artifact.Title = txtTitle.Text; artifact.Description = HttpUtility.HtmlEncode(txtDescriptor.Value); artifact.ForPurchaseOnly = chkForPurchaseOnly.Checked; artifact.ContentType = (file.ContentLength > 0) ? file.ContentType : artifact.ContentType; artifact.Save(WebUtility.GetUserName()); chkForPurchaseOnly.Checked = false; txtTitle.Text = string.Empty; txtDescriptor.Value = string.Empty; LoadDownloads(); Master.MessageCenter.DisplaySuccessMessage(LocalizationUtility.GetText("lblDownloadSaved")); } catch (Exception ex) { Logger.Error(typeof(downloadedit).Name + ".btnSave_Click", ex); Master.MessageCenter.DisplayCriticalMessage(LocalizationUtility.GetCriticalMessageText(ex.Message)); } }