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

Programatically filtering files that can be seen

1 Answer 44 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 13 Dec 2013, 02:58 PM
i was looking at the FileExplorer and wondered if it was possible to Filter Files that can be seen.
I found the following code, which i found at http://www.telerik.com/support/kb/aspnet-ajax/fileexplorer/hide-files-and-folders.aspx :
:

Public Class CustomProvider
    Inherits FileSystemContentProvider
 
    Public Sub New(ByVal context As HttpContext, ByVal searchPatterns As String(), ByVal viewPaths As String(), ByVal uploadPaths As String(), ByVal deletePaths As String(), ByVal selectedUrl As String, _
 ByVal selectedItemTag As String)
 
 
 
        MyBase.New(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, _
         selectedItemTag)
    End Sub
 
 
 
    Public Overloads Overrides Function ResolveDirectory(ByVal path As String) As 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
 
    Public Overloads Overrides Function ResolveRootDirectoryAsTree(ByVal path As String) As 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
 
    Private Function IsFiltered(ByVal name As String) As Boolean
 
 
 
        If Not name.ToLower().EndsWith(".sys".ToLower.ToString() + ".csv") Then
            Return True
        End If
 
        ' else
        Return False
    End Function
End Class

i can see how it works, and was wondering if its possible to not have to hardcode what the file 'EndsWith' in the IsFiltered Function.
My files will all be stored in the one Folder (no other Folders will be accessible to the user), and the Files in the Folder should be Filtered depending on who is viewing it.

so, for example, if you are logged in as 'London', you should only see Files that End With '_London.csv'.
equally, if you are logged in as 'Manchester', you should only see Files that End With '_Manchester.csv'.

There are many different Logins, so i would prefer not to have to have a different Folder for each Login.

1 Answer, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
answered on 13 Dec 2013, 04:43 PM
ok, i've got a very round-about way of doing it.
if there's a better way, i would still like to hear it. my way is to set the EnableFilterTextBox to True for the RadFileExplorer.

I create the defaultFilter Javascript method which calls the Explorers Filter function, passing in the value that is stored in the HiddenFiled
function defaultFilter() {
    
    $find("ctl00_Content_radCSVExplorer").filter(document.getElementById("<%=hidCurrentEnterprise.ClientID%>").value);               
}

i then hide the Filter Box and its Label, and call the defaultFilter Function, from the Javascript pageLoad method
function pageLoad() {
 
    document.getElementById("ctl00_Content_radCSVExplorer_grid_ctl00_ctl02_ctl00_FilterTextBox").style.display = "none";
    document.getElementById("ctl00_Content_radCSVExplorer_grid_ctl00_ctl02_ctl00_FilterLabel").style.display = "none";
    defaultFilter();
}
Tags
FileExplorer
Asked by
David
Top achievements
Rank 1
Answers by
David
Top achievements
Rank 1
Share this question
or