Try our conversational search powered by Generative AI!

bpedwards
Nov 18, 2008
  4987
(0 votes)

PropertyVPPDirectorySelector

After noticing that the Folder Browser Property had been release on EPiCode. I though I would share my alternative property type for rendering the list in a drop down menu, that I initially developed when CMS 5 was released.

Custom property:

public class PropertyVPPDirectorySelector : PropertyString
{
    #region Methods
    public override IPropertyControl CreatePropertyControl()
    {
    return new PropertyVPPDirectorySelectorControl();
    }
    #endregion
}

Property control:

The code below reflect amendments I made after the release of R2. R2 brought with it VPP entries for ‘Themes’, ‘UI’, ‘Util’ and ‘WebServices’ so I amended the control to only display those VPPs marked to show in the File Manager by default. setting ‘DisplayAll’ to true will return all VPP entries from the web.config. settings ‘DisplayPageFolders’ to true will include the page folders VPP as this is set to not display in the File Manager by default

public class PropertyVPPDirectorySelectorControl : PropertySelectControlBase
{
    #region Member Variables
    private List<VirtualDirectory> _directories;
    #endregion

    #region Properties
    public List<VirtualDirectory> Directories
    {
        get
        {
            if (_directories == null)
            {
                _directories = new List<VirtualDirectory>();

                VirtualPathElement element = 
EPiServerSection.Instance.VirtualPathSettings; foreach (ProviderSettings provider in element.Providers) { bool visible = false; if (provider.Name.Equals(
Settings.Instance.PageFolderVirtualPathProviderName, StringComparison.InvariantCultureIgnoreCase)) { visible = DisplayPageFolders; } else { if (DisplayAll) { visible = true; } else { bool.TryParse(
provider.Parameters["showInFileManager"],
out visible); } } if (visible) { string path = provider.Parameters["virtualPath"]; VirtualDirectory directory =
HostingEnvironment.VirtualPathProvider.GetDirectory(path); GetDirectories(_directories, directory); } } _directories.Sort(delegate(VirtualDirectory v1,
VirtualDirectory v2) {
return v1.VirtualPath.CompareTo(v2.VirtualPath); }); } return _directories; } } public bool DisplayAll { get; set; } public bool DisplayPageFolders { get; set; } #endregion #region Constructors public PropertyVPPDirectorySelectorControl() { DisplayAll = false; DisplayPageFolders = false; } public PropertyVPPDirectorySelectorControl(bool displayPageFolders) { DisplayAll = false; DisplayPageFolders = displayPageFolders; } public PropertyVPPDirectorySelectorControl(bool displayAll,
bool displayPageFolders) { DisplayAll = displayAll; DisplayPageFolders = displayPageFolders; } #endregion #region Methods protected void GetDirectories(List<VirtualDirectory> directories,
VirtualDirectory directory) { if (!directories.Contains(directory)) { directories.Add(directory); foreach (VirtualDirectory subdirectory in directory.Directories) { GetDirectories(directories, subdirectory); } } } protected override void SetupEditControls() { DropDownList dropDownListDirectories = EditControl; dropDownListDirectories.Items.Add(string.Empty); foreach (VirtualDirectory directory in Directories) { dropDownListDirectories.Items.Add(directory.VirtualPath); } if (PropertyData != null && !PropertyData.IsNull) { try { dropDownListDirectories.SelectedValue = dropDownListDirectories.Items.FindByValue(
PropertyData.Value.ToString()).Value; }
            catch { /* Do nothing */ }
        }
    }
    #endregion
}
Nov 18, 2008

Comments

Sep 21, 2010 10:32 AM

Nice one Ben. This was just what I was looking for. Skills

Please login to comment.
Latest blogs
The A/A Test: What You Need to Know

Sure, we all know what an A/B test can do. But what is an A/A test? How is it different? With an A/B test, we know that we can take a webpage (our...

Lindsey Rogers | Apr 15, 2024

.Net Core Timezone ID's Windows vs Linux

Hey all, First post here and I would like to talk about Timezone ID's and How Windows and Linux systems use different IDs. We currently run a .NET...

sheider | Apr 15, 2024

What's new in Language Manager 5.3.0

In Language Manager (LM) version 5.2.0, we added an option in appsettings.json called TranslateOrCopyContentAreaChildrenBlockForTypes . It does...

Quoc Anh Nguyen | Apr 15, 2024

Optimizely Search & Navigation: Boosting in Unified Search

In the Optimizely Search & Navigation admin view, administrators can set a certain weight of different properties (title, content, summary, or...

Tung Tran | Apr 15, 2024

Optimizely CMS – Getting all content of a specific property with a simple SQL script

When you need to retrieve all content of a specific property from a Page/Block type, normally you will use the IContentLoader or IContentRepository...

Tung Tran | Apr 15, 2024

Join the Content Recommendations Work Smarter webinar May 8th 16.00-16.45 CET with expert Aidan Swain

Learn more about Content Recommendations, with Optimizely’s very own Senior Solutions consultant, Aidan Swain . He will discuss best practices and...

Karen McDougall | Apr 12, 2024