using System; using System.Data; using System.Collections; using System.Web; using System.Web.UI; using CMS.CMSHelper; using CMS.GlobalHelper; using CMS.MediaLibrary; using CMS.PortalControls; using CMS.UIControls; public partial class CMSWebParts_MediaLibrary_MediaFileUploader : CMSAbstractWebPart { #region "Properties" /// /// Gets or sets name of the media library where the file should be uploaded. /// public string LibraryName { get { string libraryName = ValidationHelper.GetString(GetValue("LibraryName"), String.Empty); if ((string.IsNullOrEmpty(libraryName) || libraryName == MediaLibraryInfoProvider.CURRENT_LIBRARY) && (MediaLibraryContext.CurrentMediaLibrary != null)) { return MediaLibraryContext.CurrentMediaLibrary.LibraryName; } return libraryName; } set { SetValue("LibraryName", value); } } /// /// Gets or sets the destination path within the media library. /// public string DestinationPath { get { return ValidationHelper.GetString(GetValue("DestinationPath"), ""); } set { SetValue("DestinationPath", value); } } /// /// Idicates if preview upload dialog shoul displayed. /// public bool EnableUploadPreview { get { return ValidationHelper.GetBoolean(GetValue("EnableUploadPreview"), false); } set { SetValue("EnableUploadPreview", value); } } /// /// Preview suffix for identification of preview file. /// public string PreviewSuffix { get { return ValidationHelper.GetString(GetValue("PreviewSuffix"), ""); } set { SetValue("PreviewSuffix", value); } } #endregion /// /// Content loaded event handler. /// public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } /// /// Initializes the control properties. /// protected void SetupControl() { if (StopProcessing) { uploader.StopProcessing = true; } else { MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(LibraryName, CMSContext.CurrentSiteName); if (mli != null) { uploader.LibraryID = mli.LibraryID; uploader.DestinationPath = DestinationPath; uploader.EnableUploadPreview = EnableUploadPreview; uploader.PreviewSuffix = PreviewSuffix; uploader.OnNotAllowed += uploader_OnNotAllowed; } } } private void uploader_OnNotAllowed(string permissionType, CMSAdminControl sender) { if (sender != null) { sender.StopProcessing = true; } uploader.StopProcessing = true; uploader.Visible = false; messageElem.ErrorMessage = MediaLibraryHelper.GetAccessDeniedMessage("filecreate"); messageElem.DisplayMessage = true; } /// /// Reload data. /// public override void ReloadData() { base.ReloadData(); SetupControl(); } }