This is a migrated thread and some comments may be shown as answers.

Dynamically Hide Directories Depending on Security Level

4 Answers 115 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
James Taylor
Top achievements
Rank 1
James Taylor asked on 28 Oct 2010, 10:03 PM
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

4 Answers, 1 is accepted

Sort by
0
Dobromir
Telerik team
answered on 03 Nov 2010, 09:27 AM
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
0
Osama
Top achievements
Rank 2
answered on 27 Dec 2011, 10:40 AM
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?
0
Dobromir
Telerik team
answered on 27 Dec 2011, 03:13 PM
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
0
Osama
Top achievements
Rank 2
answered on 27 Dec 2011, 08:15 PM
Thank you very much this has solved my problem :)
Tags
FileExplorer
Asked by
James Taylor
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
Osama
Top achievements
Rank 2
Share this question
or