I used an example I found in these forums to show the # of files in a directory beside the name of the directory. The example seems to work fine but once I tried to change it around to suit my exact needs, I found some issues.
I wanted the following changes
1. All directories to show # of files within it including subdirectories (no problem, easily done)
2. Setting the paths in the code behind rather than within the html
3. Any change to the files (i.e. upload new file, delete file, move file) will automatically refresh the treeview
Here are the problems I experienced:
- if you set the path in the code behind, the refresh button will not update the # of files in the treeview (but will work if path are set within the html code)
- I tried to use RadFileExplorer1.TreeView.Nodes.Clear(); in the page_load to force a refresh of the treeview (which works) but this had an adverse side effect. After a file delete or file move, the changed file still appears in the grid as if the file wasn't deleted or moved until I pressed the refresh button.
Help?
I wanted the following changes
1. All directories to show # of files within it including subdirectories (no problem, easily done)
2. Setting the paths in the code behind rather than within the html
3. Any change to the files (i.e. upload new file, delete file, move file) will automatically refresh the treeview
Here are the problems I experienced:
- if you set the path in the code behind, the refresh button will not update the # of files in the treeview (but will work if path are set within the html code)
- I tried to use RadFileExplorer1.TreeView.Nodes.Clear(); in the page_load to force a refresh of the treeview (which works) but this had an adverse side effect. After a file delete or file move, the changed file still appears in the grid as if the file wasn't deleted or moved until I pressed the refresh button.
Help?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using Telerik.Web.UI.Widgets;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//RadFileExplorer1.TreeView.Nodes.Clear();
RadFileExplorer1.Configuration.ViewPaths = new string[] {@"~/Thumbs/"};
RadFileExplorer1.Configuration.UploadPaths = new string[] { @"~/Thumbs/" };
RadFileExplorer1.Configuration.DeletePaths = new string[] { @"~/Thumbs/" };
RadFileExplorer1.Configuration.ContentProviderTypeName = typeof(CustomProvider).AssemblyQualifiedName;
}
public class CustomProvider : FileSystemContentProvider
{
public CustomProvider(HttpContext context, string[] searchPatterns, string[] viewPaths, string[] uploadPaths, string[] deletePaths, string selectedUrl, string selectedItemTag)
: base(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, selectedItemTag)
{ }
public override DirectoryItem ResolveRootDirectoryAsTree(string path)
{
DirectoryItem originalDir = base.ResolveRootDirectoryAsTree(path);
string physicalPath = Context.Server.MapPath(path);
List<
DirectoryItem
> childDirItems = new List<
DirectoryItem
>();
foreach (DirectoryItem currentDir in originalDir.Directories)
{
string physicalPathChildFile = Context.Server.MapPath(currentDir.FullPath);
DirectoryItem childDirItem = new DirectoryItem(currentDir.Name + "(" + Directory.GetFiles(physicalPathChildFile, "*.*", SearchOption.AllDirectories).Length + ")",
currentDir.Location,
currentDir.FullPath,
currentDir.Tag,
currentDir.Permissions,
currentDir.Files,
currentDir.Directories
);
childDirItems.Add(childDirItem);
}
DirectoryItem dirItem = new DirectoryItem(originalDir.Name + "(" + Directory.GetFiles(physicalPath, "*.*", SearchOption.AllDirectories).Length + ")",
originalDir.Location,
originalDir.FullPath,
originalDir.Tag,
originalDir.Permissions,
originalDir.Files,
childDirItems.ToArray()
);
return dirItem;
}
public override DirectoryItem ResolveDirectory(string path)
{
DirectoryItem originalDir = base.ResolveDirectory(path);
string physicalPath = Context.Server.MapPath(path);
DirectoryItem dirItem = new DirectoryItem(originalDir.Name + "(" + Directory.GetFiles(physicalPath, "*.*", SearchOption.AllDirectories).Length + ")",
originalDir.Location,
originalDir.FullPath,
originalDir.Tag,
originalDir.Permissions,
originalDir.Files,
originalDir.Directories
);
return dirItem;
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="Telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"Form1"
runat
=
"server"
>
<
asp:ScriptManager
ID
=
"ScriptManager1"
runat
=
"server"
>
</
asp:ScriptManager
>
<
telerik:RadFileExplorer
ID
=
"RadFileExplorer1"
runat
=
"server"
Height
=
"300px"
Width
=
"804px"
Skin
=
"Forest"
>
<
Configuration
SearchPatterns
=
"*.*"
></
Configuration
>
</
telerik:RadFileExplorer
>
</
form
>
</
body
>
</
html
>