⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 directoryinformation.aspx.cs

📁 ASP C#代码实例 适合初学人士学习使用
💻 CS
字号:
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;
using System.IO;
using Microsoft.Web.UI.WebControls;

namespace Example_12_12
{
	/// <summary>
	/// DirectoryInformation 的摘要说明。
	/// </summary>
	public class DirectoryInformation : System.Web.UI.Page
	{		
		protected Microsoft.Web.UI.WebControls.TreeView Directorytree;
		protected System.Web.UI.WebControls.DropDownList DiskList;
		protected System.Web.UI.WebControls.Label InfoLabel;
		static int index = 0;
		DataTable Infodt = new DataTable("DirectoryInfo");

		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!Page.IsPostBack)
			{
				index = 0;

				Infodt.Columns.Add(new DataColumn("DirectoryID",typeof(int)));
				Infodt.Columns.Add(new DataColumn("FatherID",typeof(int)));
				Infodt.Columns.Add(new DataColumn("Info",typeof(string)));

				BindTree(Server.MapPath("/"));
			}
		}

		private void GetDiskInfo()
		{
			//
		}

		private DataTable DisplayInfo(string path,int fatherID) 
		{ 
			try 
			{ 
				DirectoryInfo di = new DirectoryInfo(path); 
				FileInfo[] subFiles = di.GetFiles(); 
				FileSystemInfo[] dirs = di.GetDirectories(); 

				DataRow rootrow = Infodt.NewRow();
				rootrow["DirectoryID"] = index;
				rootrow["Info"] = di.Name;
				rootrow["FatherID"] = fatherID;
				Infodt.Rows.Add(rootrow);

				index++;	
				DataRow[] rowList = Infodt.Select("Info='" + di.Name + "'");
				if(rowList.Length > 0)
				{	
					fatherID = Int32.Parse(rowList[0]["DirectoryID"].ToString());
				}
				foreach(FileInfo file in subFiles) 
				{ 
					DataRow row = Infodt.NewRow();
					row["DirectoryID"] = index;
					row["Info"] = file.Name;
					row["FatherID"] = fatherID;
					Infodt.Rows.Add(row);

					index++;
				}	
				
				DataTable ds = Infodt;

				foreach(DirectoryInfo diNext in dirs) 
				{ 
					DisplayInfo(path + "/" + diNext.ToString(),fatherID); 
				} 

			} 
			catch(Exception ex) 
			{ 
				InfoLabel.Text=ex.Message +"\r\n"+ InfoLabel.Text; 
			} 

			return(Infodt);
		}

		private void BindTree(String path)
		{
			Tree tree = new Tree();
			tree.BindTreeView(Directorytree,DisplayInfo(path,-1));

			TreeView treev = Directorytree;
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -