目录和档案浏览中... [英] Directory & File browsing...

查看:72
本文介绍了目录和档案浏览中...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我也是C#编程的新手,我的应用程序内部需要窗口,该窗口显示C:的目录结构,并允许您像Windows资源管理器一样选择文件.我假设这是通过treeview完成的?但是我找不到任何可以告诉我如何执行此操作的内容.

请帮忙!

谢谢,
克里斯

So I''m also new to programming in C# and I need window insided my app that shows the directory struction of the C: and lets you select files just like Windows Explorer would. I''m assuming this is done with treeview? But I''m not able to find anything that shows me how to do this.

Please Help!

Thanks,
Chris

推荐答案

您应该购买一本基础书籍并阅读. OpenFileDialog和SaveFileDialog控件是您想要的,但是如果您不知道它们的存在,并且不知道如何查找它们,则您必须没有任何引用,否则将无法正常工作
You should buy a basic book and read it. The OpenFileDialog and SaveFileDialog controls are what you want, but if you didn''t know they existed, and didn''t know how to find out about them, you must not have any references, and that''s not going to work out for you.


有很多关于如何使用TreeView以及如何检查文件系统的教程/文章/技巧.您尝试谷歌搜索了吗?

您需要考虑的一小点.由于您不想一次加载整个文件系统结构,因此您可能只想一次加载树中的一个级别.扩展节点后,您将加载该文件夹中的所有文件夹.我确定TreeView上有一个事件,您可以使用它来实现此目的(例如Expanded或类似的代码).

http://www.c-sharpcorner.com/UploadFile/nkumar/WindowsExplorerinCSharp11292005230454PM/WindowsExplorerinCSharp.aspx
There are plenty of tutorials/articles/tidbits on how to use the TreeView and how to inspect the file system. Did you try Googling?

One small point you''ll want to consider. Since you don''t want to load up the entire file system structure at once, you''ll probably only want to load one level in the tree at a time. When a node is expanded, you''d then load all the folders in that folder. I''m sure there is an event on the TreeView you can use to implement this (e.g., Expanded or something along those lines).

http://www.c-sharpcorner.com/UploadFile/nkumar/WindowsExplorerinCSharp11292005230454PM/WindowsExplorerinCSharp.aspx


听说过Google吗?

Ever heard of google?

protected void AppendDirectoriesToTreeNode(TreeNode node, string root)
{
    DirectoryInfo rootDir = new DirectoryInfo(root);
    foreach (DirectoryInfo subDir in rootDir.GetDirectories())
    {
        TreeNode subdirNode = new TreeNode(subDir.Name);
        AppendDirectoriesToTreeNode(subdirNode, subDir.FullName);
        foreach (FileInfo fileInfo in subDir.GetFiles())
        {
            subdirNode.Nodes.Add(fileInfo.Name);
        }
        node.Nodes.Add(subdirNode);
    }
}



我用这个词搜索了:

"c#treeview文件夹层次结构"

并获得了334,000条结果.



I googled this phrase:

"c# treeview folder hierarchy"

and got 334,000 results back.


这篇关于目录和档案浏览中...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆