Home - Forums-.NET - FlyTreeView (ASP.NET) - FlyTreeView for ASP.NET 2.0 - FileSystemNodes - GetFiles

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

FlyTreeView for ASP.NET 2.0 - FileSystemNodes - GetFiles
Link Posted: 02-Mar-2007 05:54
yes.  I need the file nodes navigateURL property set to corresponding aspx page.

[-] Test
   testpage1.aspx
   testpage2.aspx
   testpage3.aspx
            [-] TestSubfolder1
                 testpage10.aspx
                 testpage20.aspx
                 testpage30.aspx

I don't really need to maintain the treeview state. But I would like to see an example of that as well, if possible.

Thanks!!!
Link Posted: 02-Mar-2007 08:49
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.
Link Posted: 02-Mar-2007 10:20
Thank you!

I appreciate your time and patience.  That works well.


Best,

Matt
Link Posted: 05-Mar-2007 06:38
Hey,

Thanks again for the sample.  I have a question about how to populate the treeview using a master page.

The flytreeview would be on the masterpage, right?  Would I populate it on the content page?

Do you have a sample?  

Thanks!
Link Posted: 05-Mar-2007 11:16
It does not matter how you add nodes to treeview (master page or content page). Generally OnLoad (or Page_Load) can be used to bind/set data to any control. FlyTreeView is not an exception.