C#读取一个目录,然后点击其中一个节点动态加载他的子目录和文件,节省开销
来源:互联网 发布:上海灵娱网络怎么样 编辑:程序博客网 时间:2024/06/06 04:10
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
using System.IO;
public partial class test_Default9 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TreeNode tp = new TreeNode("0", "0");
Fun(@"D:/WINDOWS", tp);
//for (int i=0; i < 10; i++)
//{
// Button bnt = new Button();
// bnt.Text = "下载";
// bnt.ID = i.ToString();
// bnt.Click += new EventHandler(bnt_Click);
// TreeNode tn = new TreeNode(bnt,i.ToString());
// TreeView1.Nodes.Add(tn);
//}
//TreeView1.CollapseAll();
}
}
public void Fun(string path, TreeNode tnn)
{
path += "//";
TreeNode tn = new TreeNode(path, path);
if (tnn.Value == "0")
{
tnn = tn;
TreeView1.Nodes.Add(tnn);
}
//没有子目录
foreach (string name in Directory.GetFiles(path))
{
int n = name.LastIndexOf(@"/");
int tnw = name.Length;
string s = name.Substring(n + 1, tnw - n - 1);
TreeNode tn1 = new TreeNode(s, name);
tnn.ChildNodes.Add(tn1);
}
foreach (string name in Directory.GetDirectories(path))
{
int n = name.LastIndexOf(@"/");
int tnw = name.Length;
string s = name.Substring(n + 1, tnw - n - 1);
TreeNode tn2 = new TreeNode(s, name);
tnn.ChildNodes.Add(tn2);
// Fun(name, tn2);
}
}
// public static void fun(string path)
//{
//
// if (Directory.GetDirectories(path).Length == 0)
//
// Response.Write(path);
// foreach (string name in Directory.GetFiles(path))
// Response.Write(name);
//
//
// elsehttp://163.foloda.com/topic/bj/homechild/
//
// Response.Write(path);
// foreach (string name in Directory.GetDirectories(path))
// fun(name);
// foreach (string name in Directory.GetFiles(path))
// Response.Write(name);
//
//}
void bnt_Click(object sender, EventArgs e)
{
Response.Write(((Button)sender).ID.ToString());
}
protected void Button1_Click(object sender, EventArgs e)
{
FileInfo MyFileInfo;
//String MyFileName= Server.MapPath("Images") + "//" +
// this.ListBox1.SelectedItem.Text;
String MyFileName = @"F:/完成的项目/1.27服务器/4.30/software.rar";
MyFileInfo = new FileInfo(MyFileName);
Response.Clear();
Response.AddHeader("Content-Disposition",
"attachment; filename=aaa.rar");
//Response.AddHeader("Content-Disposition",
// "attachment; filename=" + this.ListBox1.SelectedItem.Text);
Response.AddHeader("Content-Length", MyFileInfo.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(MyFileName);
Response.End();
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
FileInfo MyFileInfo;
//String MyFileName= Server.MapPath("Images") + "//" +
// this.ListBox1.SelectedItem.Text;
String MyFileName = TreeView1.SelectedNode.Value.ToString();
int n = TreeView1.SelectedNode.Value.ToString().LastIndexOf(@"/");
int tn = TreeView1.SelectedNode.Value.ToString().Length;
string s = TreeView1.SelectedNode.Value.ToString().Substring(n + 1, tn - n - 1);
if (File.Exists(TreeView1.SelectedNode.Value.ToString()))
{
MyFileInfo = new FileInfo(MyFileName);
Response.Clear();
Response.AddHeader("Content-Disposition",
"attachment; filename=" + s.ToString());
//Response.AddHeader("Content-Disposition",
// "attachment; filename=" + this.ListBox1.SelectedItem.Text);
Response.AddHeader("Content-Length", MyFileInfo.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(MyFileName);
Response.End();
}
else
{
Fun(TreeView1.SelectedNode.Value.ToString(), TreeView1.SelectedNode);
}
}
protected void bt1_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "s", "alert('1')", true);
}
protected void Button2_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "s", "alert('2')", true);
}
}
- C#读取一个目录,然后点击其中一个节点动态加载他的子目录和文件,节省开销
- python 读取一个目录下的所有目录和文件
- 给定一个目录,递归的列出下面所有的子目录和文件
- Linux下使用Shell脚本删除一个目录下的所有子目录和文件
- 给定任意一个目录,以树形方式展现出该目录中的子目录和文件
- tar打包一个目录时,去掉其中的几个子目录
- 做练习时写了一个调用DOS命令删文件夹及子目录和文件的C#程序
- 如何复制一个目录里面的所有目录和文件
- 复制一个目录里面的所有目录和文件
- 如何复制一个目录里面的所有目录和文件
- C#实现的列出目录下所有子目录和文件的程序(附思路)
- C#实现的列出目录下所有子目录和文件的程序(附思路)
- C# 遍历子目录和文件
- 遍历一个指定的目录(包含子目录和文件),用Jdom把该目录的树形结构写入xml文件中
- 列出某个目录下的所有子目录和文件
- 递归列出某目录的所有子目录和文件
- 获取指定目录下所有的子目录和文件
- Java递归打印目录下所有的子目录和文件
- DS18B20的驱动过程
- 点滴中学英语------Core & Corner 方法
- Timesten for java guide 学习笔记
- w3的XML學習筆記之一
- Java thread synchronized
- C#读取一个目录,然后点击其中一个节点动态加载他的子目录和文件,节省开销
- 搞么事,Liferay 中文化
- 正则表达式的JS验证!
- 使用java发送email
- 程序员的七种武器
- jquery使用方法简介
- sap视频教程
- spring + ibatis jpetstore 摘要
- 编写类String的构造函数,析构函数和赋值函数