using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace HelloWorldMyTekTipsSample
{
/// <summary>
/// Summary description for this demo.
/// </summary>
public class BrowseNetworkStuff : System.Web.UI.Page
{
protected Microsoft.Web.UI.WebControls.TreeView TreeView1;
protected System.Web.UI.WebControls.Label statusMessage;
private void FillTree(string currentDir, Microsoft.Web.UI.WebControls.TreeNode node) {
string[] dirList = System.IO.Directory.GetDirectories(currentDir);
string[] fileList = System.IO.Directory.GetFiles(currentDir);
int amountOfDirs;
int amountOfFiles;
// Fill the Tree with dirs from the current directory
foreach (string dir in dirList) {
Microsoft.Web.UI.WebControls.TreeNode dirNode = new Microsoft.Web.UI.WebControls.TreeNode();
string[] finalDir = dir.ToString().Split('\\');
dirNode.Text = finalDir.GetValue(finalDir.Length-1).ToString();
string[] finalDir2 = dirNode.Text.ToString().Split('/');
dirNode.Text = finalDir2.GetValue(finalDir2.Length-1).ToString();
//dirNode.Text = dir.ToString();
dirNode.Expanded = false;
dirNode.Expandable = Microsoft.Web.UI.WebControls.ExpandableValue.Always;
dirNode.ImageUrl = HttpContext.Current.Server.MapPath("/webctrl_client/1_0/Images/folder.gif");
dirNode.ExpandedImageUrl = HttpContext.Current.Server.MapPath("/webctrl_client/1_0/Images/folderopen.gif");
node.Nodes.Add(dirNode);
amountOfDirs = System.IO.Directory.GetDirectories(dir.ToString() + '/').Length;
amountOfFiles = System.IO.Directory.GetFiles(dir.ToString() + '/').Length;
if (amountOfDirs > 0 || amountOfFiles > 0) {
FillTree(dir.ToString() + '/', dirNode);
}
}
// Fill the Tree with files from the current directory
foreach (string fil in fileList) {
Microsoft.Web.UI.WebControls.TreeNode fileNode = new Microsoft.Web.UI.WebControls.TreeNode();
string[] finalFile = fil.ToString().Split('/');
fileNode.Text = finalFile.GetValue(finalFile.Length-1).ToString();
fileNode.NavigateUrl=fil.ToString();
fileNode.Expanded = false;
fileNode.Expandable = Microsoft.Web.UI.WebControls.ExpandableValue.Auto;
fileNode.ImageUrl = HttpContext.Current.Server.MapPath("/webctrl_client/1_0/Images/html.gif");
node.Nodes.Add(fileNode);
}
}
private void FillTreeRoot() {
//
//
ApplyStyle(TreeView1);
string rootDir = HttpContext.Current.Server.MapPath("/SomeRootDirIfYouNeedIt/");
Microsoft.Web.UI.WebControls.TreeNode node = new Microsoft.Web.UI.WebControls.TreeNode();
node.Text = "Hello World";
node.Expanded = true;
node.ImageUrl = HttpContext.Current.Server.MapPath("/webctrl_client/1_0/Images/folder.gif");
node.ExpandedImageUrl = HttpContext.Current.Server.MapPath("/webctrl_client/1_0/Images/folderopen.gif");
TreeView1.Nodes.Add(node);
FillTree(rootDir, node);
}
private void ApplyStyle(Microsoft.Web.UI.WebControls.TreeView TreeView) {
TreeView.Style.Clear();
TreeView.DefaultStyle.Add("font-family", "Verdana");
TreeView.DefaultStyle.Add("font-size", "10pt");
TreeView.DefaultStyle.Add("background-color", "#ffffff");
TreeView.SelectedStyle.Add("color", "black");
TreeView.SelectedStyle.Add("background-color", "#ffffff");
Microsoft.Web.UI.WebControls.CssCollection style = new Microsoft.Web.UI.WebControls.CssCollection();
style.Add("color" ,"#ff6600");
TreeView.HoverStyle = style;
string m_ButtonLinkStyle = "this.style.color='#000000'";
string m_ButtonLinkHoverStyle = "this.style.color='#ff6600'";
TreeView.HoverStyle.Add("onmouseover", m_ButtonLinkHoverStyle);
TreeView.HoverStyle.Add("onmouseout", m_ButtonLinkStyle);
TreeView.ShowLines = false;
TreeView.SystemImagesPath = "/images/TreeControl";
TreeView.Nodes.Clear();
}
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
FillTreeRoot();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}