public override bool UpdateItem(ContentItem item, Control editor) { SelectingUploadCompositeControl composite = (SelectingUploadCompositeControl)editor; HttpPostedFile postedFile = composite.UploadControl.PostedFile; if (postedFile != null && !string.IsNullOrEmpty(postedFile.FileName)) { IFileSystem fs = Engine.Resolve <IFileSystem>(); string directoryPath = Engine.Resolve <IDefaultDirectory>().GetDefaultDirectory(item); if (!fs.DirectoryExists(directoryPath)) { fs.CreateDirectory(directoryPath); } string fileName = Path.GetFileName(postedFile.FileName); fileName = Regex.Replace(fileName, InvalidCharactersExpression, "-"); string filePath = VirtualPathUtility.Combine(directoryPath, fileName); fs.WriteFile(filePath, postedFile.InputStream); item[Name] = Url.ToAbsolute(filePath); return(true); } if (composite.SelectorControl.Url != item[Name] as string) { item[Name] = composite.SelectorControl.Url; return(true); } return(false); }
protected override Control AddEditor(Control container) { SelectingUploadCompositeControl control = (SelectingUploadCompositeControl)base.AddEditor(container); control.SelectorControl.SelectableExtensions = FileSelector.ImageExtensions; control.SelectorControl.SelectableTypes = typeof(N2.Definitions.IFileSystemFile).Name; return(control); }
protected override Control AddEditor(Control container) { SelectingUploadCompositeControl control = (SelectingUploadCompositeControl)base.AddEditor(container); control.SelectorControl.SelectableExtensions = FileSelector.AudioExtensions + "," + FileSelector.ImageExtensions + "," + FileSelector.MovieExtensions; control.SelectorControl.SelectableTypes = typeof(N2.Definitions.IFileSystemFile).Name; control.SelectorControl.Placeholder(GetLocalizedText("Placeholder") ?? Placeholder); return(control); }
protected override Control AddEditor(Control container) { SelectingUploadCompositeControl composite = new SelectingUploadCompositeControl(); composite.ID = Name; composite.UploadLabel.Text = UploadText ?? "Upload"; container.Controls.Add(composite); return(composite); }
protected override Control AddEditor(Control container) { SelectingUploadCompositeControl composite = new SelectingUploadCompositeControl(); composite.ID = Name; composite.UploadLabel.Text = UploadText ?? "Upload"; composite.SelectorControl.Placeholder(GetLocalizedText("Placeholder") ?? Placeholder); container.Controls.Add(composite); return(composite); }
public override bool UpdateItem(ContentItem item, Control editor) { SelectingUploadCompositeControl composite = (SelectingUploadCompositeControl)editor; HttpPostedFile postedFile = composite.UploadControl.PostedFile; if (postedFile != null && !string.IsNullOrEmpty(postedFile.FileName)) { IFileSystem fs = Engine.Resolve <IFileSystem>(); string directoryPath; if (uploadDirectory == string.Empty) { directoryPath = Engine.Resolve <IDefaultDirectory>().GetDefaultDirectory(item); } else { directoryPath = uploadDirectory; } if (!fs.DirectoryExists(directoryPath)) { fs.CreateDirectory(directoryPath); } string fileName = Path.GetFileName(postedFile.FileName); fileName = Regex.Replace(fileName, InvalidCharactersExpression, "-"); string filePath = VirtualPathUtility.Combine(directoryPath, fileName); if (Engine.Config.Sections.Management.UploadFolders.IsTrusted(fileName)) { fs.WriteFile(filePath, postedFile.InputStream); } else { throw new Security.PermissionDeniedException("Invalid file name"); } item[Name] = Url.ToAbsolute(filePath); return(true); } if (composite.SelectorControl.Url != item[Name] as string) { item[Name] = composite.SelectorControl.Url; return(true); } return(false); }
protected override Control AddEditor(Control container) { var composite = new SelectingUploadCompositeControl(); composite.ID = Name; composite.UploadLabel.Text = UploadText ?? "Upload"; composite.SelectorControl.Placeholder(GetLocalizedText("Placeholder") ?? Placeholder); if (ReadOnly) { composite.SelectorControl.Attributes["readonly"] = "readonly"; } container.Controls.Add(composite); return(composite); }
/// <summary>Adds a required field validator.</summary> /// <param name="container">The container control for this validator.</param> /// <param name="editor">The editor control to validate.</param> protected override Control AddRequiredFieldValidator(Control container, Control editor) { SelectingUploadCompositeControl composite = editor as SelectingUploadCompositeControl; if (composite != null) { RequireEitherFieldValidator rfv = new RequireEitherFieldValidator(); rfv.ID = Name + "_rfv"; rfv.ControlToValidate = composite.SelectorControl.ID; rfv.OtherControlToValidate = composite.UploadControl.ID; rfv.Display = ValidatorDisplay.Dynamic; rfv.Text = GetLocalizedText("RequiredText") ?? RequiredText; rfv.ErrorMessage = GetLocalizedText("RequiredMessage") ?? RequiredMessage; editor.Controls.Add(rfv); return(rfv); } return(null); }
public override void UpdateEditor(ContentItem item, Control editor) { SelectingUploadCompositeControl composite = (SelectingUploadCompositeControl)editor; composite.Select(item[Name] as string); }