如何将文件夹添加到.net 中的列表框?

发布于 2024-08-26 10:22:22 字数 242 浏览 4 评论 0原文

我有一个列表框,我想在指定位置添加一个文件夹/目录,我已经使用了代码,

 string path = "E:\\shruti\\MyDir";
 DirectoryItem folder = new DirectoryItem(path);
 lstBurnItems.Items.Add(folder); //add folder to listbox

但它无法正常工作... 我应该做什么才能成功?

i have a list box and i want to add a folder/directory to that which is at the specified location i have used the code

 string path = "E:\\shruti\\MyDir";
 DirectoryItem folder = new DirectoryItem(path);
 lstBurnItems.Items.Add(folder); //add folder to listbox

but its not working fine...
what should i do to get success??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘寄 2024-09-02 10:22:22

下面的示例展示了如何将文件夹中的文件夹添加到 ListBox 以及如何将文件夹中的文件添加到 ListBox 中。抱歉,你没说清楚,所以我都给了。

        string path = @"E:\shruti\MyDir";

        string[] dirs = Directory.GetDirectories(path);

        // For folders in the directory
        foreach(string dir in dirs)
            lstBurnItems.Items.Add(dir);


        // For files in the directory
        string[] dirFiles = Directory.GetFiles(path);

        foreach (string file in dirFiles)
            lstBurnItems.Items.Add(file);

Below is an example showing how to add folders within a folder to a ListBox and to add Files within a folder into a ListBox. Sorry, you weren't clear so I gave both.

        string path = @"E:\shruti\MyDir";

        string[] dirs = Directory.GetDirectories(path);

        // For folders in the directory
        foreach(string dir in dirs)
            lstBurnItems.Items.Add(dir);


        // For files in the directory
        string[] dirFiles = Directory.GetFiles(path);

        foreach (string file in dirFiles)
            lstBurnItems.Items.Add(file);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文