Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > FileExplorer > Dynamically Hide Directories Depending on Security Level

Not answered Dynamically Hide Directories Depending on Security Level

Feed from this thread
  • James Taylor avatar

    Posted on Oct 28, 2010 (permalink)

    Hi. I am working on a project that will use the RadFileExplorer to show directories for specific security levels.

    I know that there is a way to hardcode the items (see below code) which will be visible however, since I need to show directories and hide directories depending on the user's security level, I need it to work dynamically. I would like to pass in a list of security levels and use a switch statement to hide/show the appropriate directories depending on the user's security level.

                public override DirectoryItem ResolveRootDirectoryAsTree(string path)
                    {
                    DirectoryItem originalFolder = base.ResolveRootDirectoryAsTree(path);
                    DirectoryItem[] originalDirectories = originalFolder.Directories;
                    List<DirectoryItem> filteredDirectories = new List<DirectoryItem>();

                    // Filter the folders
                    foreach (DirectoryItem originalDir in originalDirectories)
                        {
                        if (!this.IsFiltered(originalDir.Name))
                            {
                            filteredDirectories.Add(originalDir);
                            }
                        }
                    DirectoryItem newFolder = new DirectoryItem(originalFolder.Name, originalFolder.Location, originalFolder.FullPath, originalFolder.Tag, originalFolder.Permissions, originalFolder.Files, filteredDirectories.ToArray());

                    return newFolder;
                    }

                private bool IsFiltered(string name)
                    {
                   //I NEED THIS AREA TO BE DYNAMIC
                


                    if (name.ToLower().EndsWith(".sys") ||
                        name.ToLower().Contains("_sys") ||
                        name == "Secure Directory1" ||
                        name == "Secure Directory2")
                        {
                        return true;
                        }

                    // else
                    return false;
                    }

    Thanks,
    James

    Reply

  • Dobromir Dobromir admin's avatar

    Posted on Nov 3, 2010 (permalink)

    Hi James,

    In order to achieve the required functionality you can use one of the following approaches:
    • Set different ViewPaths, UploadPaths, DeletePaths to the RadFileExplorer depending on the user permissions, e.g.:
      switch (securityLevel)
      {
          case "securitylevel1":
              RadFileExplorer1.Configuration.ViewPaths = new string[] { "~/folder1", "~/folder2" };
              RadFileExplorer1.Configuration.UploadPaths = new string[] {"~/folder1", "~/folder2"};
              RadFileExplorer1.Configuration.DeletePaths = new string[] { "~/folder1", "~/folder2" };
          case "securitylevel2":
              RadFileExplorer1.Configuration.ViewPaths = new string[] { "~/folder3", "~/folder4" };
              RadFileExplorer1.Configuration.UploadPaths = new string[] { "~/folder3", "~/folder4" };
              RadFileExplorer1.Configuration.DeletePaths = new string[] { "~/folder3", "~/folder4" };
      }
    • You can access the Page object of the page where RadFileExplorer resides through the HttpContext. You can find more information on the subject in the following KB:
      Get reference to the Page object inside a custom FileBrowserContentProvider
    Please let us know if this helps.

    All the best,
    Dobromir
    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

    Reply

  • Osama avatar

    Posted on Dec 27, 2011 (permalink)

    Hi James,

    I have similar scenario where I need to change the ViewPaths dynamically based on the user's selection from a RadComboBox. But when I run the code below the RadFileBrowser control is not updated and the ViewPaths remain unchanged.

    The only way I can change the ViewPaths if I put the code in PageLoad event and it runs only once the first time only. Any changes to the ViewPaths variable after the first PageLoad is ignored.

    protected void RadComboBoxScope_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            if (RadComboBoxScope.SelectedValue == "MyFiles")
                RadFileExplorer1.Configuration.ViewPaths = new string[] { "~/MyFiles" };
           
            else
                RadFileExplorer1.Configuration.ViewPaths = new string[] { "~/AllFiles" };
      
        }

    Is there any special method that forces the control to update the ViewPaths or to refresh it in order to be able to directly change it from the combobox?

    Reply

  • Dobromir Dobromir admin's avatar

    Posted on Dec 27, 2011 (permalink)

    Hi Osama,

    The latest moment of the page live cycle where the RadFileExplorer's properties ViewPaths / DeletePaths / UploadPaths can be set is the Page_Load event, and SelectedIndexChanged event of the RadComboBox occurs after that. Nevertheless, your scenario can be implemented using the following approach approach:
    • You need to check which control causes postback
    • Then, change the paths based on the clicked button. Please note that you need to clear the old nodes in order to force the RadFileExplorer to repopulate its content.

    For your convenience I have attache a sample project implementing the above mentioned approach.

    Kind regards,
    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
    Attached files

    Reply

  • Osama avatar

    Posted on Dec 27, 2011 (permalink)

    Thank you very much this has solved my problem :)

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > FileExplorer > Dynamically Hide Directories Depending on Security Level
Related resources for "Dynamically Hide Directories Depending on Security Level"

ASP.NET FileExplorer Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  |  Step-by-step Tutorial  ]