Disabling context menu items and upload buttons

3 posts, 1 answers
  1. Joe
    Joe avatar
    51 posts
    Member since:
    Oct 2008

    Posted 06 Sep 2011 Link to this post

    I need to disable a certain context menu item (upload) and disable the upload button from the toolbar. 

    I found this code to disable the toolbar upload function (and it works)

               Dim toolBar As RadToolBar = RadFileExplorer1.ToolBar
               ' Remove commands from the ToolBar control; 
               Dim i As Integer = 0
               While i < toolBar.Items.Count
                   If toolBar.Items(i).Value = "Delete" Then
                       toolBar.Items.RemoveAt(i)
                       ' Next item 
                       Continue While
     
                   ElseIf toolBar.Items(i).Value = "Upload" Then
                       toolBar.Items.RemoveAt(i)
                       ' Next item 
                       Continue While
                   End If
     
                   ' Next item 
                   i += 1
               End While

    Is there similar code to disable the context menu item (upload) in the code behind? I want to control this based on user login as I will use an IF statement to check the login name.

    Thanks,
    Joe
  2. Answer
    Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 07 Sep 2011 Link to this post

    Hi Joe,

    By design, RadFileExplorer enables the upload functionality if the current selected folder (or its parent folder(s)) is listed in the UploadPaths property. If upload permissions is not provided for the specific folder the Upload button on the toolbar and the context menu items will not be rendered at all.

    The recommended approach to disable Upload button and context menus according to the logged user is to modify the UploadPaths property.

    If you need to manually remove the context menu items you can use the following code:
    Dim treeViewContextMenu As RadContextMenu = fileExplorer.TreeView.ContextMenus(0)
           ' Remove commands from the TreeView's ContextMenus control;
           i = 0
           While i < treeViewContextMenu.Items.Count
               If treeViewContextMenu.Items(i).Value = "Delete" Then
                   treeViewContextMenu.Items.RemoveAt(i)
                   ' Next item
                   Continue While
     
               ElseIf treeViewContextMenu.Items(i).Value = "Upload" Then
                   treeViewContextMenu.Items.RemoveAt(i)
                   ' Next item
                   Continue While
               End If
     
               ' Next item
               i += 1
           End While
     
     
     
           Dim gridContextMenu As RadContextMenu = fileExplorer.GridContextMenu
           ' Remove commands from the GridContextMenu control;
     
           i = 0
           While i < gridContextMenu.Items.Count
               If gridContextMenu.Items(i).Value = "Delete" Then
                   gridContextMenu.Items.RemoveAt(i)
                   ' Next item
                   Continue While
     
               ElseIf gridContextMenu.Items(i).Value = "Upload" Then
                   gridContextMenu.Items.RemoveAt(i)
                   ' Next item
                   Continue While
               End If
     
               ' Next item
               i += 1
           End While

    A example of how to manually disable Delete and Upload commands is available in the following KB article:
    Remove the "Delete" and "Upload" commands from the RadFileExplorer control


    Kind regards,
    Dobromir
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Joe
    Joe avatar
    51 posts
    Member since:
    Oct 2008

    Posted 07 Sep 2011 Link to this post

    Thanks! Just what I needed....

    Joe
Back to Top