Building Some Web TreeViews

The TreeView control in ASP.NET 2.0 is used to display hierarchical data, such as table of contents or file directory in a tree structure. In most applications that I do, I use the TreeView control to show file directory structure. I was able to create a class that populates a TreeView provided with a physical directory structure residing on the same computer as to where the server is running. Rename the file below to .dll and use it as a reference on your web application. Once added to your web application usage would be:


using System;
// include other namespaces as needed
using PhysicalTreeView;

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string location;
        pTreeView ptv = new pTreeView(location);
        // the example below is valid without specifying the "isWeb" to false.
        pTreeView ptv = new pTreeView("~/");
        ptv.isWeb = false;
        ptv.PopulateTree(TreeView1);
    }
}

By default, the variable location will treat the path as a virtual path. If you want to specify a specific physical directory, you can specify the 8 character directory format as a location value but you need to specify the property “isWeb” as “false” and as shown above. The “TreeView1” is assumed to be a TreeView control placed onto the ASPX file. For testing purposes, you can put in your code behind the following code without placing a TreeView control in your ASPX file but will output the same.


TreeView TreeView1 = new TreeView();
string location;
pTreeView ptv = new pTreeView(location);
// the example below is valid without specifying the "isWeb" to false.
pTreeView ptv = new pTreeView("~/");
ptv.isWeb = false;
ptv.PopulateTree(TreeView1);

this.Form.Controls.Add(TreeView1);

Physical Drive TreeView DLL

The challenge for me is to bring the same functionality to a SourceSafe database which is despite having a directory like structure isn’t directory based at all when accessed programmatically. Furthermore, the DLL provided with Visual Source Safe 2005 isn’t a native .NET object but a COM interop one.

Luckily, using the same logic behind the previous DLL, I managed to create a DLL to populate a TreeView from a SourceSafe database. The constructor needs only 3 parameters namely the database location, username, and password.

Sample usage would be:


using ProjectTreeView;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        string location, user, password;
        // Populate your own values

        ssTreeView stv = new ssTreeView(location, user, password);
        stv.BuildSourceSafeTree(TreeView1);

    }
}

Same with the code above, the code assumes that there’s a TreeView control instance in the ASPX file that has an ID of “TreeView1”.

Sourcesafe TreeView

For questions, feel free to add some comments. 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Blog Stats

  • 3,965 hits
April 2008
S M T W T F S
« Mar   May »
 12345
6789101112
13141516171819
20212223242526
27282930  

%d bloggers like this: