62,046
社区成员
发帖
与我相关
我的任务
分享
protected void Page_Load(object sender, EventArgs e)
{
TreeNode rootNode = new TreeNode();
this.TreeView1.Nodes.Add(rootNode);
ShowFolder(Server.MapPath("~/"),ref rootNode);
}
void ShowFolder(string Path,ref TreeNode node)
{
node.Text = System.IO.Path.GetFileName(Path.TrimEnd('\\'));
string[] Dirs = System.IO.Directory.GetDirectories(Path);
foreach (string sDir in Dirs)
{
TreeNode cNode = new TreeNode();
node.ChildNodes.Add(cNode);
ShowFolder(sDir, ref cNode);
}
}
private void saveList()
{
ArrayList list = new ArrayList();
SaveFileDialog save = new SaveFileDialog();
save.Filter = "(*.Lst)|*.Lst";
save.Title = "Save List";
if (save.ShowDialog() == DialogResult.OK)
{
try
{
foreach (ListViewItem item in this.listView1.Items)
{
list.Add(item);
}
FileStream fs = new FileStream(save.FileName, FileMode.Create, FileAccess.Write);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, list);
fs.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void openList()
{
OpenFileDialog open = new OpenFileDialog();
open.Title = "Load List";
if (open.ShowDialog() == DialogResult.OK)
{
try
{
this.listView1.Items.Clear();
FileStream fs = new FileStream(open.FileName, FileMode.Open, FileAccess.Read);
BinaryFormatter bf = new BinaryFormatter();
ArrayList conff = (ArrayList)bf.Deserialize(fs);
fs.Close();
foreach (ListViewItem item in conff)
{
this.listView1.Items.Add(item);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}