Attempt at Filtering FileExplorer

3 posts, 1 answers
  1. Kurt Kluth
    Kurt Kluth avatar
    152 posts
    Member since:
    Oct 2009

    Posted 05 Nov 2014 Link to this post

    Trying to limit the results that are returned to a FileExplorer and it works sporadically and quite possibly we are missing something.  If a file exists for a Credit Union it will display as it should however if there isn't one found it will return all the records in that folder (which we do not want).  After it shows all the files if I click the refresh button within the FileExplorer it will then show there are no results.  There is only two possible outcomes:

    if a file exists for that credit union, show the file
    if does not exist, show no files
    Public Shared iASI_Num As Integer
        Public Shared Property GetAsiNum() As Integer
                Return iASI_Num
            End Get
            Set(ByVal value As Integer)
                iASI_Num = value
            End Set
        End Property
        Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        End Sub
        Protected Function GetVisibleControls() As Telerik.Web.UI.FileExplorer.FileExplorerControls
            Dim explorerControls As Telerik.Web.UI.FileExplorer.FileExplorerControls = 0
            explorerControls = explorerControls Or Telerik.Web.UI.FileExplorer.FileExplorerControls.AddressBox
            explorerControls = explorerControls Or Telerik.Web.UI.FileExplorer.FileExplorerControls.Grid
            explorerControls = explorerControls Or Telerik.Web.UI.FileExplorer.FileExplorerControls.ListView
            explorerControls = explorerControls Or Telerik.Web.UI.FileExplorer.FileExplorerControls.Toolbar
            explorerControls = explorerControls Or Telerik.Web.UI.FileExplorer.FileExplorerControls.TreeView
            explorerControls = explorerControls Or Telerik.Web.UI.FileExplorer.FileExplorerControls.ContextMenus
            Return explorerControls
        End Function
        Private Sub Page_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
            If Not String.IsNullOrEmpty(Session("ASI_Num")) Then
                If Session("asi_num") <> 0 Then
                    iASI_Num = Session("ASI_Num")
                    'set properties according to configuration panel
                    FileExplorer1.Configuration.SearchPatterns = New String() {"*.pdf"}
                    FileExplorer1.VisibleControls = GetVisibleControls()
                    FileExplorer1.EnableOpenFile = True
                    FileExplorer1.DisplayUpFolderItem = False
                    FileExplorer1.AllowPaging = False
                    FileExplorer1.EnableCreateNewFolder = False
                    FileExplorer1.Configuration.AllowFileExtensionRename = False
                    FileExplorer1.Upload.InitialFileInputsCount = 1
                    FileExplorer1.Upload.MaxFileInputsCount = 1
                    If (FileExplorer1.VisibleControls And Telerik.Web.UI.FileExplorer.FileExplorerControls.Grid) = 0 Then
                        FileExplorer1.ExplorerMode = Telerik.Web.UI.FileExplorer.FileExplorerMode.Thumbnails
                    End If
                    If (FileExplorer1.VisibleControls And Telerik.Web.UI.FileExplorer.FileExplorerControls.ListView) = 0 Then
                        FileExplorer1.ExplorerMode = Telerik.Web.UI.FileExplorer.FileExplorerMode.[Default]
                    End If
                    FileExplorer1.Configuration.UploadPaths = New String() {"~/PDF/ECPay"}
                    FileExplorer1.Configuration.DeletePaths = New String() {"~/PDF/ECPay"}
                    '#region assign-provider_vb
                    FileExplorer1.Configuration.ContentProviderTypeName = GetType(ExtendedFileProvider).AssemblyQualifiedName
                End If
            End If
        End Sub
    End Class
    Public Class ExtendedFileProvider
        Inherits Telerik.Web.UI.Widgets.FileSystemContentProvider
        Dim iAsi_Num As Integer = ECPayManagement.GetAsiNum
        'constructor must be present when overriding a base content provider class
        'you can leave it empty
        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, _
        End Sub
        Public Overloads Overrides Function ResolveDirectory(ByVal path As String) As Telerik.Web.UI.Widgets.DirectoryItem
            'get the directory information
            Dim baseDirectory As Telerik.Web.UI.Widgets.DirectoryItem = MyBase.ResolveDirectory(path)
            'remove files that we do not want to see
            Dim files As New System.Collections.Generic.List(Of Telerik.Web.UI.Widgets.FileItem)()
            For Each file As Telerik.Web.UI.Widgets.FileItem In baseDirectory.Files
                If IsFiltered(file.Name.ToString) Then
                End If
            Dim newDirectory As New Telerik.Web.UI.Widgets.DirectoryItem(baseDirectory.Name, baseDirectory.Location, baseDirectory.FullPath, baseDirectory.Tag, baseDirectory.Permissions, files.ToArray(), _
            'return the updated directory information
            Return newDirectory
        End Function
        Public Overrides Function StoreFile(file As Telerik.Web.UI.UploadedFile, path As String, name As String, ParamArray arguments As String()) As String
            Dim extension As String = name.Substring(name.LastIndexOf("."))
            name = iAsi_Num & extension 'put here your logic for getting the client id
            Return MyBase.StoreFile(file, path, name)
        End Function
        Private Function IsFiltered(name As String) As Boolean
            If name.ToString = CStr(iAsi_Num & ".pdf") Then
                Return True
            End If
            ' else
            Return False
        End Function
  2. Kurt Kluth
    Kurt Kluth avatar
    152 posts
    Member since:
    Oct 2009

    Posted 10 Nov 2014 Link to this post

    Any suggestions?
  3. Answer
    Vessy avatar
    1660 posts

    Posted 10 Nov 2014 Link to this post

    Hi Kurt,

    The experienced behavior is expected since the provided ResolveDirectory() implementation is listing all files in the folder, except for the current one. In order to achieve the desired by you functionality you will need to add the filtered files to the result filteredFiles collection:
    Public Overrides Function ResolveDirectory(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 Me.IsFiltered(originalFile.Name) Then
            End If
        Dim newFolder As New DirectoryItem(originalFolder.Name, originalFolder.Location, originalFolder.FullPath, originalFolder.Tag, originalFolder.Permissions, filteredFiles.ToArray(), _
        Return newFolder
    End Function

    The other thing you should pay attention to is that the Page_Load event is the latest moment of the page-lice-cycle where FileExplorer can be configured in order to function properly.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top