Home / Community & Support / Knowledge Base / RadControls for ASP.NET and ASP.NET AJAX / FileExplorer / Hide certain directories and files in RadFileExplorer

Hide certain directories and files in RadFileExplorer

Article Info

Rating: 4

Article information

Article relates to

RadFileExplorer 

Created by

 Fiko, Telerik

Last modified

 January 27, 2009

Last modified by

 Fiko, Telerik


This article demonstrates how to filter(hide) desired files from the RadFileExplorer control.  For example, this approach can be applied in case that you need to hide system files.
The best and the most simple way to do this is by using a CustomContentProvider. Bellow are the steps that we need to implement in order to get the provider to filter the items that we need to hide.
  • First we need to inherit the base class - Telerik.Web.UI.Widgets.FileSystemContentProvider.
  • Then we need to override its ResolveDirectory() method of the base class as follows :

    C# :
    public override DirectoryItem ResolveDirectory(string path)  
    {  
        DirectoryItem originalFolder = base.ResolveDirectory(path);  
        FileItem[] originalFiles = originalFolder.Files;  
        List<FileItem> filteredFiles = new List<FileItem>();  
     
        // Filter the files  
        foreach (FileItem originalFile in originalFiles)  
        {  
            if (!this.IsFiltered(originalFile.Name))  
            {  
                filteredFiles.Add(originalFile);  
            }  
        }  
     
        DirectoryItem newFolder = new DirectoryItem(originalFolder.Name, originalFolder.Location, originalFolder.FullPath, originalFolder.Tag, originalFolder.Permissions, filteredFiles.ToArray(), originalFolder.Directories);  
     
        return newFolder;  

    VB.NET :
        Public Overloads Overrides Function ResolveDirectory(ByVal path As StringAs DirectoryItem  
            Dim originalFolder As DirectoryItem = MyBase.ResolveDirectory(path)  
            Dim originalFiles As FileItem() = originalFolder.Files  
            Dim filteredFiles As New List(Of FileItem)()  
     
            ' Filter the files  
            For Each originalFile As FileItem In originalFiles  
                If Not Me.IsFiltered(originalFile.Name) Then 
                    filteredFiles.Add(originalFile)  
                End If 
            Next 
     
            Dim newFolder As New DirectoryItem(originalFolder.Name, originalFolder.Location, originalFolder.FullPath, originalFolder.Tag, originalFolder.Permissions, filteredFiles.ToArray(), _  
             originalFolder.Directories)  
     
            Return newFolder  
        End Function 
     

        In this function we filtered the files.

  •  Then we need to exclude the directories that are system directories. This can be done in the ResolveRootDirectoryAsTree() function and we need to override it as follows : 

    C# :
    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;  

    VB.NET :
        Public Overloads Overrides Function ResolveRootDirectoryAsTree(ByVal path As StringAs DirectoryItem  
            Dim originalFolder As DirectoryItem = MyBase.ResolveRootDirectoryAsTree(path)  
            Dim originalDirectories As DirectoryItem() = originalFolder.Directories  
            Dim filteredDirectories As New List(Of DirectoryItem)()  
     
            ' Filter the folders   
            For Each originalDir As DirectoryItem In originalDirectories  
                If Not Me.IsFiltered(originalDir.Name) Then 
                    filteredDirectories.Add(originalDir)  
                End If 
            Next 
            Dim newFolder As New DirectoryItem(originalFolder.Name, originalFolder.Location, originalFolder.FullPath, originalFolder.Tag, originalFolder.Permissions, originalFolder.Files, _  
             filteredDirectories.ToArray())  
     
            Return newFolder  
        End Function 
     
  • In both of the overridden functions we used the IsFiltered() function. This function is a client function and for demonstration purposes we implement it as follows :

    C# :
    private bool IsFiltered(string name)  
    {  
        if (name.ToLower().EndsWith(".sys") || name.ToLower().Contains("_sys"))  
        {  
            return true;  
        }  
     
        // else  
        return false;  

    VB.NET :
  •     Private Function IsFiltered(ByVal name As StringAs Boolean    
            If name.ToLower().EndsWith(".sys"OrElse name.ToLower().Contains("_sys"Then    
                Return True    
            End If    
        
            ' else     
            Return False    
        End Function    
     
After implementing all of the above steps, the RadFileExplorer control will filter all of the items(folders and files), that end with ‘.sys’ or contain “_sys” in their name. The full working example can be found attached to the thread.

Comments

If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.