Show only folders in RadFileExplorer
Description
In this article you will see how to configure RadFileExplorer to show only the folders inside the passed path to the end user.
Solution
Option 1
A way to achieve the described scenario is to show only the folders' tree to the users, by configuring the FileExplorer's VisibleControls
property by removing the right grid view of the control:
<telerik:RadFileExplorer ID="FileExplorer1" runat="server" EnableCopy="true" VisibleControls="Toolbar,TreeView,ContextMenus,AddressBox">
<Configuration ViewPaths="~/" DeletePaths="~/" UploadPaths="~/"/>
</telerik:RadFileExplorer>
Option 2
Another possible approach, in case you want to keep visible both the TreeView and the Grid, is to handle the ExplorerPopulated
server-side event event of RadFileExplorer. Inthis event you have access to all items bound to the grid, so you can remove the files from the items collection like follows:
<telerik:RadFileExplorer ID="FileExplorer1" runat="server" EnableCopy="true" OnExplorerPopulated="RadFileExplorer1_ExplorerPopulated">
<Configuration ViewPaths="~/" DeletePaths="~/" UploadPaths="~/" />
</telerik:RadFileExplorer>
protected void RadFileExplorer1_ExplorerPopulated(object sender, RadFileExplorerPopulatedEventArgs e)
{
List<FileBrowserItem> items = e.List;
if (e.ControlName == "grid")
{
int i = 0;
while (i < items.Count)
{
if (items[i] is FileItem)
{
items.Remove(items[i]);
}
else
{
i++;
}
}
}
}
Protected Sub RadFileExplorer1_ExplorerPopulated(ByVal sender As Object, ByVal e As RadFileExplorerPopulatedEventArgs)
Dim items As List(Of FileBrowserItem) = e.List
If e.ControlName = "grid" Then
Dim i As Integer = 0
While i < items.Count
If TypeOf items(i) Is FileItem Then
items.Remove(items(i))
Else
i += 1
End If
End While
End If
End Sub