To get physical location you need to use
Server.MapPath(..) method.
To get client url, you need to use ResolveUrl(..) method.
So finally the function looks like
private const string ROOT_FOLDER = \"~/test/\";
public static void AddNodes(FlyTreeNodeCollection nodes, string directoryPath, System.Web.UI.Page page)
{
string physicalRoot = page.Server.MapPath(ROOT_FOLDER);
DirectoryInfo directory = new DirectoryInfo(Path.Combine(physicalRoot, directoryPath));
if (!directory.Exists) return;
DirectoryInfo[] subDirectories = directory.GetDirectories();
foreach (DirectoryInfo subDir in subDirectories)
{
FlyTreeNode ftn = new FlyTreeNode();
ftn.Text = HttpUtility.HtmlEncode(subDir.Name);
ftn.Value = subDir.Name;
nodes.Add(ftn);
try
{
// do not set populate on demand for nodes that have no nested directories
ftn.PopulateNodesOnDemand = subDir.GetDirectories().Length > 0;
}
catch (Exception ex)
{
// add a child node that shows that there was an exception trying to get its child nodes
AddExceptionNode(ftn.ChildNodes, ex);
}
}
FileInfo[] files = directory.GetFiles();
foreach (FileInfo file in files)
{
FlyTreeNode ftn = new FlyTreeNode();
ftn.Text = HttpUtility.HtmlEncode(file.Name);
ftn.Value = file.Name;
ftn.NavigateUrl = page.ResolveUrl(ROOT_FOLDER + directoryPath + \"/\" + file.Name).Replace(\"//\",\"/\");
nodes.Add(ftn);
}
}
Notice, that ROOT_FOLDER is a virtual path.