2 d28905 d28905 于 2016.04.19 11:00 提问

想做一个文档管理系统

语言是winform,服务器端搭建了ftp服务,我现在想法是一个tree view控件,一个list view控件,tree view控件怎么显示服务器目录

3个回答

caozhy
caozhy   Ds   Rxr 2016.04.19 11:12
d28905
d28905 求打什么指导我想把tree view显示的根目录定位到我的电脑上具体的文件夹怎么操作
一年多之前 回复
d28905
d28905 谢谢
一年多之前 回复
CSDNXIAON
CSDNXIAON   2016.04.19 11:13

文档管理系统解决方案
文档管理系统解决方案
----------------------同志你好,我是CSDN问答机器人小N,奉组织之命为你提供参考答案,编程尚未成功,同志仍需努力!

d28905
d28905   2016.04.20 10:04

public Form1()
{
InitializeComponent();
}

    private void Form1_Load(object sender, EventArgs e)
    {
        treeView1.Nodes.Add(new TreeNode("文档管理系统", DriveInfo.GetDrives()
            .Select(x => new TreeNode(x.Name) { Tag = x }).ToArray()) { Tag = "root" });
    }

    private void treeView1_BeforeExpand(object sender, TreeViewCancelEventArgs e)
    {
        e.Node.Nodes.Cast<TreeNode>().ToList().ForEach(x =>
            {
                try
                {
                    if (x.Nodes.Count == 0)
                    {
                        TreeNode[] nodes = new TreeNode[] { };
                        if (x.Tag.GetType() == typeof(DriveInfo))
                        {
                            var item = x.Tag as DriveInfo;
                            nodes = Directory.GetDirectories(item.Name)
                                .Select(y => new DirectoryInfo(y))
                                .Select(y => new TreeNode(y.Name) { Tag = y })
                                .ToArray();
                        }
                        if (x.Tag.GetType() == typeof(DirectoryInfo))
                        {
                            var item = x.Tag as DirectoryInfo;
                            nodes = Directory.GetDirectories(item.FullName)
                                .Select(y => new DirectoryInfo(y))
                                .Select(y => new TreeNode(y.Name) { Tag = y })
                                .ToArray();
                        }
                        x.Nodes.AddRange(nodes);
                    }
                }
                catch { }
            });
    }

    private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
    {
        if (e.Node.Tag.GetType() == typeof(string) && e.Node.Text == "文档管理系统")
        {
            listView1.Items.AddRange(DriveInfo.GetDrives()
                .Select(x => new ListViewItem(new string[] { x.Name, x.DriveType.ToString(), x.DriveType == DriveType.Fixed ? (x.TotalSize / 1048576 / 1024).ToString() + "GB" : "" }))
                .ToArray());

        }
        if (e.Node.Tag.GetType() == typeof(DriveInfo))
        {
            listView1.Items.Clear();
            listView1.Items.AddRange(Directory.GetDirectories((e.Node.Tag as DriveInfo).Name)
                .Select(x => new DirectoryInfo(x)).OrderBy(x => x.Name)
                .Select(x => new ListViewItem(new string[] { x.Name, "Folder", "", x.CreationTime.ToString()})).ToArray());
            listView1.Items.AddRange(Directory.GetFiles((e.Node.Tag as DriveInfo).Name, "*.*", SearchOption.TopDirectoryOnly)
                .Select(x => new FileInfo(x)).OrderBy(x => x.Name)
                .Select(x => new ListViewItem(new string[] { x.Name, "File", (x.Length / 1024).ToString() + "KB", x.CreationTime.ToString() })).ToArray());
        }
        if (e.Node.Tag.GetType() == typeof(DirectoryInfo))
        {
            listView1.Items.Clear();
            listView1.Items.AddRange(Directory.GetDirectories((e.Node.Tag as DirectoryInfo).FullName)
                .Select(x => new DirectoryInfo(x)).OrderBy(x => x.Name)
                .Select(x => new ListViewItem(new string[] { x.Name, "Folder", "", x.CreationTime.ToString() })).ToArray());
            listView1.Items.AddRange(Directory.GetFiles((e.Node.Tag as DirectoryInfo).FullName, "*.*", SearchOption.TopDirectoryOnly)
                .Select(x => new FileInfo(x)).OrderBy(x => x.Name)
                .Select(x => new ListViewItem(new string[] { x.Name, "File", (x.Length / 1024).ToString() + "KB", x.CreationTime.ToString() })).ToArray());
        }
    }

    private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
    {

    }

    private void listView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!