|
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class SiteStructure : System.Web.UI.UserControl {
protected void Page_Load(object sender, EventArgs e) {
if (!Page.IsPostBack)
LoadTreeStructure();
}
private void LoadTreeStructure() {
tvStructure.Nodes.Clear();
AddFolderNode(tvStructure.Nodes, Server.MapPath("~"));
}
private void AddFolderNode(TreeNodeCollection nodeCollection, string folderPath) {
// Add a new node for the folder to the node collection.
int i = folderPath.LastIndexOf(Path.DirectorySeparatorChar);
string FolderName = folderPath.Substring(i + 1);
TreeNode FolderNode = new TreeNode(FolderName);
FolderNode.SelectAction = TreeNodeSelectAction.None;
nodeCollection.Add(FolderNode);
// Add a new node for each file in the folder.
string RootPath = Server.MapPath("~");
foreach (string FileName in Directory.GetFiles(folderPath, "*.aspx")) {
TreeNode FileNode = new TreeNode(Path.GetFileName(FileName));
FileNode.NavigateUrl = "~/" + FileName.Substring(RootPath.Length);
FolderNode.ChildNodes.Add(FileNode);
}
// Add a new node for each sub-folder.
foreach (string SubFolderPath in Directory.GetDirectories(folderPath))
AddFolderNode(FolderNode.ChildNodes, SubFolderPath);
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I began programming on my Commodore 64 at around the age of 12. After migrating to DOS and then Windows, I decided to take on the Web. Several languages and platforms later, I have settled in with .NET nicely. I am currently the owner of a software consulting company and lead application developer for a learning-based technology consultation company.
The love of a finished application is usually at war with the desire to improve it as soon as it's released (they're never really finished).