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: 27-Feb-2007 05:19
I'm evaluationg FlyTreeView for ASP.NET 2.0.  Do you have a working sample with additional code in FileSystemNodes.cs that populates the file list using getFiles?  

I tried but could get the navigateURL to work.

Thanks,
Link Posted: 27-Feb-2007 05:49
Do you need files to be present in treeview structure?

How do you use the NavigateUrl property?
Link Posted: 27-Feb-2007 05:52
thanks for the quick response.

I need to build a web file browser with FlyTreeView, so I need to populate the  folder nodes with file nodes and then build a string for the navigateurl property.

Seems futile to re-create the wheel.  Thanks again for the help.

Matt
Link Posted: 27-Feb-2007 06:25
So you're using frameset or IFRAME to show the content of a file?

It is quite easy to add another loop to add files along with directories to the output of FileSystemNodes.

You should just create a copy of
        DirectoryInfo[] subDirectories = directory.GetDirectories();
        foreach (DirectoryInfo subDir in subDirectories)
        {
           ...
        }


So that it will use FileInfo[] files = directory.GetFiles() and loops through files array.
Link Posted: 27-Feb-2007 07:54
I'm not using frameset or IFRAME.  

I want the filename in the node and the full url in the navigateurl property.  The ui is going to use ie to view the file.

I know what I have to do, I don't know how to do it.  I know I need to loop through the files array, but I need to add nodes.

How do I change this code?

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.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);
            }
            
        }
    }
Link Posted: 27-Feb-2007 08:24
Probably this code should work. I didn't test it though.

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;
        ftn.NavigateUrl = subDir.FullName;
        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 = file.FullName;
        nodes.Add(ftn);
    }
}
Link Posted: 27-Feb-2007 08:42
Thanks for that.  I think I can take it from there.  How do you sort the flytreeview?

The folders/files are in a very strange order.

Thanks again for great support.
Link Posted: 27-Feb-2007 09:18
Probably there should be some simple sort method to sort subDirectories and files arrays.
But from my point of view, GetDirectories and GetFiles return entries in an alphabetical order.
Link Posted: 27-Feb-2007 10:12
Sort is not in alpha order on network drive.  Weird.

Hey I'm having trouble with installation.  The sample code works fine.  But it doesn't work in my project.

The flytreeview is not populating on demand.  What is in the sample.precompiled.dll??
Link Posted: 27-Feb-2007 10:40
Everything is ok with installation...
I needed to set the PopulateNodes event.

Is it possible to save the flytreeview state?

After I view a file in the IE Browser,  I go back to the FlytreeView and it's collapsed again.

Anyway to save the state?

Thanks again!!!