RadFileExplorer: Enable/disable CreateNewFolder client-side

3 posts, 1 answers
  1. Arnstein
    Arnstein avatar
    12 posts
    Member since:
    Mar 2008

    Posted 10 Nov 2011 Link to this post

    Hi,
    Using RadFileExplorer, I want the user to be able to create new subfolders. However, I want to limit this ability to certain existing folders.
    Example: The user may create subfolders in folder "Pictures", but not in folder "Agreement".
    I can use the server-side OnItemCommand event and cancel the operation if RadFileExplorerEventArgs.Command=="CreateDirectory" and RadFileExplorerEventArgs.Path is not a folder that allows subfolders, but at this point the user has already entered the name of the new folder and pressed OK.
    The best solution,  I think, would be to disable the Create folder button (and context-menu choice) client-side, depending on which folder is the current folder. Something like this (for the toolbar button):

     

    <telerik:RadFileExplorer OnClientFolderChange="OnClientFolderChange" EnableCreateNewFolder="True"....

    Javascript:

    function OnClientFolderChange(sender, args) {
        if(args.get_path() != 
    "Pictures") {
            var tbitem = 
    sender.get_toolbar().findItemByValue("NewFolder");
            
    if(tbitem != 
    null{
                tbitem.disable();
            }
        }
    }

    Unfortunately, this does not work. The toolbar button gets disabled, but then enabled again, immediately after.

    In addition, this would be solved very easily if the EnableCreateNewFolder property of RadFileExplorer could be set client-side, using javascript. Is that possible, or do you guys have a different solution?

    Thanks,

    Arnstein

  2. Arnstein
    Arnstein avatar
    12 posts
    Member since:
    Mar 2008

    Posted 14 Nov 2011 Link to this post

    Here is an update to my original post.
    It would have been much easier if the EnableCreateNewFolder property of RadFileExplorer had been accessible using javascript (maybe it is?), but I managed to solve the problem this way:
    .ASPX:
    <telerik:RadFileExplorer ID="rfe" EnableCreateNewFolder="True"
        OnClientFolderChange="OnClientFolderChange" 
    ...

    .CS:
    rfe.TreeView.OnClientContextMenuShown = "OnClientContextMenuShown";

    JavaScript:
    function OnClientFolderChange(sender, args) {
        
    var p = 
    args.get_path();
        
    var show = (p.indexOf("/ROOT/Pictures") >= 
    0);
        
    var tb = sender.get_toolbar();
        
    var tbitem = 
    tb.findItemByValue("NewFolder");
        
    if(tbitem != null
    {
            tbitem.set_visible(show);
        }
    }
    function OnClientContextMenuShown(sender, args) {
        
    var p = 
    args.get_node().get_value();
        
    var show = (p.indexOf("/ROOT/Pictures"
    >= 0);
        
    var cmitem = 
    args.get_menu().findItemByValue("NewFolder");
        
    if(cmitem != null
    {
            cmitem.set_enabled(show);
        }
    }

    If anyone has a better solution, please let me know.

    Regards,

    Arnstein
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 15 Nov 2011 Link to this post

    Hi Arnstein,

    The problem that you experience with the initial code comes from the fact that the state of the toolbar buttons is updated on every RadFileExplorer's inner AJAX request. After the ClientFolderChanged event is fired the explorer initiates new AJAX call to load the folder's content.

    In order to achieve the required functionality, you can use the approach from your initial post but executed in the ClientFolderLoaded event.

    Regarding the implementation of a client-side property controlling EnableCreateNewFolder, I have brought this to the attention of the developers and we will consider such implementation.

    Best wishes,
    Dobromir
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top