Home - Forums-.NET - FlyTreeView (ASP.NET) - Where are the files?

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

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

Where are the files?
Link Posted: 12-Oct-2006 08:16
Hi,
I searched for this but didn't find anything...
Maybe I'm missing something very simple, but I don't see any files in the directories either on the demo or the sample that I built. Does it not show files? Only folders?!
Link Posted: 12-Oct-2006 10:36
By default, it shows directories only.
You should refer to App_Code/FileSystemNodes.cs file in demo app.
It creates nodes using directory.GetDirectories(); call.
It is quite simple to add additional code to add nodes from directory.GetFiles(); call.
Link Posted: 12-Feb-2008 09:26
I'm fairly new to this. Could you be so kind as to explain in detail how to make the files viewable. What code to use and where? If I can get this to work, than I'll purchase it as is. Thanks in advance!!
Link Posted: 13-Feb-2008 01:14
Open the App_Code/FileSystemNodes.cs file in of the demo project.
Replace its content with:

using System;
using System.Web;
using System.IO;
using NineRays.WebControls;

public class FileSystemNodes
{
    private const string ROOT_FOLDER = "c:\\";
    public static void AddNodes(FlyTreeNodeCollection nodes, string directoryPath)
    {
        DirectoryInfo directory = new DirectoryInfo(Path.Combine(ROOT_FOLDER, 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.GetFileSystemInfos().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);
            }
        }

        try
        {
            FileInfo[] files = directory.GetFiles();
            foreach (FileInfo file in files)
            {
                FlyTreeNode ftn = new FlyTreeNode();
                ftn.Text = HttpUtility.HtmlEncode(file.Name);
                ftn.Value = file.Name;
                ftn.ImageUrl = "$file_xml";
                nodes.Add(ftn);
            }
        }
        catch (Exception ex)
        {
            // add a child node that shows that there was an exception trying to get its child nodes
            AddExceptionNode(nodes, ex);
        }

    }
    private static void AddExceptionNode(FlyTreeNodeCollection nodes, Exception ex)
    {
        FlyTreeNode ftn = new FlyTreeNode();
        ftn.Text = HttpUtility.HtmlEncode(ex.Message);
        ftn.NodeTypeID = "errorType";
        nodes.Add(ftn);
    }

}


Works for me.
Link Posted: 13-Feb-2008 03:32
Thanks