+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Selecting a folder from the FileManager

Selecting a folder from the FileManager

2 posts, 0 answered
  1. Tristan
    Tristan avatar
    22 posts
    Registered:
    30 Mar 2009
    19 May 2010
    Link to this post
    I had a quick look around but couldn't find anything on this.

    Is there a way to use the Filemanager to select a folder rather than a file and have it return the path to that folder. For example if I have a folder called "ImageGallery" and I want the user to be able to select that folder rather than an image inside it, is that possible?

    I realise I can get the user to enter the path and go from there but by using the filemanager I can get rid of any possible spelling errors.

    Thanks again.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    19 May 2010
    Link to this post
    Hello Tristan,

    You should create a custom WebEditor. Below is a sample code that you can use as an example or modify it appropriately depending on your custom needs.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Cms.Web.UI;
    using Telerik.FileManager;
    using System.Drawing.Design;
      
    /// <summary>
    /// Summary description for DirectoryWebUItypeEditor
    /// </summary>
    public class DirectoryWebUItypeEditor : WebUITypeEditor<String>
    {
        public DirectoryWebUItypeEditor()
        {
        }
      
        public override string Value
        {
            get
            {
                base.EnsureChildControls();
                string path = this.manageFiles.SelectedFolder.FullName;
                if (path != string.Empty)
                {
                    string appPath = Page.Server.MapPath(Page.Request.ApplicationPath);
                    if (path != appPath)
                    {
                        if (!appPath.EndsWith("\\"))
                        {
                            appPath += "\\";
                        }
                        path = path.Replace(appPath, "~\\");
                    }
                    else
                        path = "~\\";
                    path = path.Replace("\\", "/");
                }
                return path;
            }
            set
            {
                base.EnsureChildControls();
                string path = value;
            }
        }
      
      
        public override UITypeEditorEditStyle GetEditStyle()
        {
            return UITypeEditorEditStyle.Modal;
        }
      
      
        public override void EditValue(string value)
        {
            this.Value = value;
        }
      
        protected override void CreateChildControls()
        {
            this.Controls.Clear();
      
            this.manageFiles = new ManageFiles();
            this.manageFiles.SetFilesGridColumnVisibility(false, false, false);
            this.manageFiles.SelectedFolderChanged += new FileSystemEventHandler(fileManager_SelectedFolderChanged);
            this.Controls.Add(this.manageFiles);
        }
      
        void fileManager_SelectedFolderChanged(object source, FileSystemEventArgs e)
            {
                base.OnValueChanged(new ValueChangedEventArgs(e.Path));
            }
      
        private ManageFiles manageFiles;
    }

    Basically you have to return the folder instead of the file to the Value property.

    Regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
2 posts, 0 answered