473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

TreeView control

Ok,

I am creating a directory browsing app and am using the obout.com
TreeView control. This is exactly what I was looking for, as of right
now my code is quite sloppy and I plan on cleaning it up.

Here is my setup:
Client--->IIS Server--->File Server

when I populate the treeview, I do so all on the first time they hit
the page. this is very costly for the IIS Server CPU and it takes
awhile to load.

There is an option in this treeview to load the data from a specially
formatted XML file. Would reading all the dirs, subdirs and files into
an XML file first, then loading this XML file into Treeview help at
all? I guess I should start by cleaning up my code... here it is below:
m_UserPath is the logged in user's directory that I am getting all the
dirs and files for.
It enters PopulateTree first.
any help would be appreciated!! thanks!

public void PopulateTree() {
// Add the root name with username and My Computer icon
oTree.AddRootNode(m_UserName, "xpMyComp.gif");

// Root Directory
// This part gets all the dirs for the root, then enters the
GetContents
// each time it finds a sub directory, it will drill down all the
way
// until it is complete
int i = 0;
foreach (string dir in
System.IO.Directory.GetDirectories(m_UserPath)) {
string dirName = dir.Substring(dir.LastIndexOf("\\") + 1);
oTree.Add("root", "a" + i, dirName, false, null, null);
oTree.
GetContents("a" + i, m_UserPath + "\\" + dirName);

// Get files under the root directories
string[] files = System.IO.Directory.GetFiles(m_UserPath + "\\" +
dirName);
if (files.Length > 0) {
int x = 0;
foreach (string file in files) {
string fileName = file.Substring(file.LastIndexOf("\\") + 1);
oTree.Add("a" + i, "a" + i + "_" + x, fileName, false,
"help_page.gif", null);
x += 1;
}
}

i += 1;
}

// Get Files under the root dir
foreach (string file in System.IO.Directory.GetFiles(m_UserPath)) {
string fileName = file.Substring(file.LastIndexOf("\\") + 1);
oTree.Add("root", "a" + i, fileName, false, "help_page.gif", null);

i += 1;
}

oTree.FolderIcons = "TreeIcons/Icons";
oTree.FolderStyle = "TreeIcons/Styles/Classic";

// Write treeview to your page.
TreeView.Text = oTree.HTML();
}

// This will traverse the p_Folder passed to it, each time
// it finds a subDir, it will re-enter the method and add
// subfolders recursively, then it will add files for each dir
public void GetContents(string p_ParentID, string p_Folder) {
// Dirs
string[] subDir = System.IO.Directory.GetDirectories(p_Folder);
if (subDir.Length > 0) {
int x = 0;
foreach (string sub in subDir) {
string subDirName = sub.Substring(sub.LastIndexOf("\\") + 1);

string thisID = p_ParentID + "_" + x;
oTree.Add(p_ParentID, thisID, subDirName, false, null, null);

// Now let's find if there is anymore subdirs
string[] subDir2 = System.IO.Directory.GetDirectories(sub);
if (subDir2.Length > 0) {
GetContents(thisID,sub);
}
// Check for files under this directory, and add them if relevant
string[] files = System.IO.Directory.GetFiles(p_Folder + "\\" +
subDirName);
if (files.Length > 0) {
foreach (string file in files) {
x += 1;
string folderID = thisID;
string fileID = thisID + "_" + x;
string fileName = file.Substring(file.LastIndexOf("\\") + 1);
oTree.Add(folderID, fileID, fileName, false, "help_page.gif",
null);
}
}

x += 1;
}
}
}

Nov 16 '05 #1
0 3866

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: SoKool | last post by:
Can anyone point me to a site where I can get a free treeview control to use in ASP .NET or any tutorial that can help me build my own treeview control. I intend to use a treeview to generate a...
8
by: Hrvoje Voda | last post by:
What is wrong in this code? private void tree_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.KeyCode == Keys.Enter ) {
3
by: Peter | last post by:
Hello, We are inserting a side menu to our application using a class that is writing HTML on all our pages. This is a part of the code as an example: writer.Write(" <table WIDTH=""100%""...
4
by: Ben Coats | last post by:
Hey, I'm trying to find code for an Explorer-style Directory ComboBox. (You know, it display "Desktop", "My Computer", all drives, etc., but it has a treeview control inside the combobox so that...
10
by: p3t3r | last post by:
I have a treeview sourced from a SiteMap. I want to use 2 different CSS styles for the root level nodes. The topmost root node should not have a top border, all the other root nodes should have a...
1
by: musosdev | last post by:
Hi guys I was using the Microsoft.Web.UI.WebControls extra namespace in my application to provide me with a TreeView control. I was using specifically ..GetNodeFromIndex(), SelectedNodeIndex and...
2
by: rolf.oltmans | last post by:
Hello all, I need to place treeview control in Grid control. I need to place it in a grid because I need to show calendar against every node. Is placing a treeview in grid possible? If I need...
1
by: doemon | last post by:
Hi, I'm working on a pagination control and I need to dynamically rerender a treeview to display the next set of nodes depending on which page we're on. For example, page 1 will dispaly only...
0
by: noneya22 | last post by:
I want to use a TreeView control as a one-level, vertical navigation menu. I'm using this control currently with a SiteMapDataSource and .sitemap file. I've written code that associates an image...
0
by: jiing | last post by:
Hi all, I want to use sting(the same as Node.Text) to judge if a node exists in TreeView. I've tried several ways, but seems all failed. could anybody help me? Thanks in advance. //My...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.