使用Treeview模拟操作系统的文件系统
2006-10-11 14:20
218 查看
default.aspx 代码:
<%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="false" Inherits="OsFilesytem._default" %>
<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm2</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<iewc:TreeView id="TreeView1" runat="server" AutoPostBack="True" BackColor="#EEEEEE"></iewc:TreeView>
</form>
</body>
</HTML>
default.aspx.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 Microsoft.Web.UI.WebControls;
using System.IO;
namespace OsFilesytem
{
/// <summary>
/// WebForm2 的摘要说明。
/// </summary>
public class _default : System.Web.UI.Page
{
protected Microsoft.Web.UI.WebControls.TreeView TreeView1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
TreeNode newnode=new TreeNode();
newnode.Text="我的电脑";
this.TreeView1.Nodes.Add(newnode);
try
{
string[] drives = System.IO.Directory.GetLogicalDrives();
foreach (string str in drives)
{
TreeNode tmpNd;
tmpNd=new TreeNode();
tmpNd.Text=str;
this.TreeView1.Nodes[0].Nodes.Add(tmpNd);
//ProcessDirectory(str,tmpNd);
}
}
catch (System.IO.IOException)
{
this.Response.Write("I/O错误!");
}
catch (System.Security.SecurityException)
{
this.Response.Write("没有访问权限!");
}
}
}
public void ProcessDirectory(string targetDirectory,TreeNode TN)
{
if(targetDirectory.ToString()==@"A:\")
{
return;
}
TreeNode tmpNd;
try
{
// Process the list of files found in the directory
string [] fileEntries = Directory.GetFiles(targetDirectory);
foreach(string fileName in fileEntries)
{
tmpNd=new TreeNode();
//只显示文件名
tmpNd.Text=fileName.Substring(fileName.LastIndexOf(@"\")+1);
//显示文件 全名(路径+名称)
//tmpNd.Text=fileName;
TN.Nodes.Add(tmpNd);
}
// Recurse into subdirectories of this directory
string [] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach(string subdirectory in subdirectoryEntries)
{
tmpNd=new TreeNode();
//只显示文件夹名
tmpNd.Text=subdirectory.Substring(subdirectory.LastIndexOf(@"\")+1);
//显示文件夹 全名(路径+名称)
//tmpNd.Text=subdirectory;
TN.Nodes.Add(tmpNd);
//ProcessDirectory(subdirectory,tmpNd);
}
}
catch
{
}
}
/// <summary>
/// 获得当前结点的全名
/// </summary>
/// <param name="TN">当前结点</param>
/// <returns>全名</returns>
private string GetFullName(TreeNode TN)
{
if(TN.Text=="我的电脑")
{
return "我的电脑";
}
string str_fullname="";
while(((TreeNode)TN.Parent).Text!="我的电脑")
{
str_fullname = TN.Text + @"\" + str_fullname;
TN=(TreeNode)TN.Parent;
}
str_fullname =TN.Text + str_fullname;
return str_fullname;
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.TreeView1.Expand += new Microsoft.Web.UI.WebControls.ClickEventHandler(this.TreeView1_Expand);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void TreeView1_Expand(object sender, Microsoft.Web.UI.WebControls.TreeViewClickEventArgs e)
{
TreeNode TNS=this.TreeView1.GetNodeFromIndex(e.Node);
foreach(TreeNode TN in TNS.Nodes)
{
this.ProcessDirectory(this.GetFullName(TN),TN);
}
}
}
}
OVER
<%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="false" Inherits="OsFilesytem._default" %>
<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm2</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<iewc:TreeView id="TreeView1" runat="server" AutoPostBack="True" BackColor="#EEEEEE"></iewc:TreeView>
</form>
</body>
</HTML>
default.aspx.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 Microsoft.Web.UI.WebControls;
using System.IO;
namespace OsFilesytem
{
/// <summary>
/// WebForm2 的摘要说明。
/// </summary>
public class _default : System.Web.UI.Page
{
protected Microsoft.Web.UI.WebControls.TreeView TreeView1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
TreeNode newnode=new TreeNode();
newnode.Text="我的电脑";
this.TreeView1.Nodes.Add(newnode);
try
{
string[] drives = System.IO.Directory.GetLogicalDrives();
foreach (string str in drives)
{
TreeNode tmpNd;
tmpNd=new TreeNode();
tmpNd.Text=str;
this.TreeView1.Nodes[0].Nodes.Add(tmpNd);
//ProcessDirectory(str,tmpNd);
}
}
catch (System.IO.IOException)
{
this.Response.Write("I/O错误!");
}
catch (System.Security.SecurityException)
{
this.Response.Write("没有访问权限!");
}
}
}
public void ProcessDirectory(string targetDirectory,TreeNode TN)
{
if(targetDirectory.ToString()==@"A:\")
{
return;
}
TreeNode tmpNd;
try
{
// Process the list of files found in the directory
string [] fileEntries = Directory.GetFiles(targetDirectory);
foreach(string fileName in fileEntries)
{
tmpNd=new TreeNode();
//只显示文件名
tmpNd.Text=fileName.Substring(fileName.LastIndexOf(@"\")+1);
//显示文件 全名(路径+名称)
//tmpNd.Text=fileName;
TN.Nodes.Add(tmpNd);
}
// Recurse into subdirectories of this directory
string [] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach(string subdirectory in subdirectoryEntries)
{
tmpNd=new TreeNode();
//只显示文件夹名
tmpNd.Text=subdirectory.Substring(subdirectory.LastIndexOf(@"\")+1);
//显示文件夹 全名(路径+名称)
//tmpNd.Text=subdirectory;
TN.Nodes.Add(tmpNd);
//ProcessDirectory(subdirectory,tmpNd);
}
}
catch
{
}
}
/// <summary>
/// 获得当前结点的全名
/// </summary>
/// <param name="TN">当前结点</param>
/// <returns>全名</returns>
private string GetFullName(TreeNode TN)
{
if(TN.Text=="我的电脑")
{
return "我的电脑";
}
string str_fullname="";
while(((TreeNode)TN.Parent).Text!="我的电脑")
{
str_fullname = TN.Text + @"\" + str_fullname;
TN=(TreeNode)TN.Parent;
}
str_fullname =TN.Text + str_fullname;
return str_fullname;
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.TreeView1.Expand += new Microsoft.Web.UI.WebControls.ClickEventHandler(this.TreeView1_Expand);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void TreeView1_Expand(object sender, Microsoft.Web.UI.WebControls.TreeViewClickEventArgs e)
{
TreeNode TNS=this.TreeView1.GetNodeFromIndex(e.Node);
foreach(TreeNode TN in TNS.Nodes)
{
this.ProcessDirectory(this.GetFullName(TN),TN);
}
}
}
}
OVER
相关文章推荐
- 使用Treeview模拟操作系统的文件系统(B/S)
- 虚拟机安装Debian7 后无法使用共享文件夹,提示:无法更新运行时文件夹共享状态: 在客户机操作系统内装载共享文件夹文件系统时出错。
- 在XP操作系统中使用批处理命令删除系统垃圾文件
- 使用恢复操作系统的方式异机恢复RAC到单实例文件系统
- 常见的操作系统使用的文件系统整理
- 常见的操作系统使用的文件系统整理
- HPUX操作系统使用tar命令恢复系统备份带指定文件
- MFS文件系统安装、使用详解
- 使用 /sys 文件系统访问 Linux 内核
- Linux 查看磁盘分区、文件系统、使用情况的命令和相关工具介绍
- 使用pyspark时报错--FileNotFoundError: [WinError 2] 系统找不到指定的文件。
- Hadoop Shell命令(基于linux操作系统上传下载文件到hdfs文件系统基本命令学习)
- Linux操作系统的简单指令及如何使用vim编写一个程序,然后使用gcc查看【预处理】、【编译】、【汇编】、【链接】各阶段文件的内容。
- ceph客户端挂在ceph集群存储作为本地文件系统来使用
- VS2013中 勾选在共享DLL中使用MFC 报错 系统找不到指定文件 参考解决办法
- 【hadoop 2.6】hadoop 2.6集群环境搭建及文件系统使用
- 使用系统调用来处理文件
- 网络文件系统nfs文件系统使用
- 今天在Mac机器上使用了Flex Builder编辑了一个源代码文件,保存后使用vim命令去打开时发现系统自动在每一行的结尾添加了^M符号,其实^M在Linux/Unix中是非常常见的,也就是我们在Win中见过的/r回车符号。由于编辑软件的编码问题,某些IDE的编辑器在编辑完文件之后会自动加上这个^M符号。看起来对我们的源代码没有任何影响,其实并不然,当我们把源代码文件Check In到svn之类
- UFFS文件系统使用心得