[英]how to add folder to a listbox in .net?
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?? 但它不能正常工作...我应该怎么做才能获得成功?
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
. 下面的示例显示了如何将文件夹内的文件夹添加到
ListBox
以及如何将文件夹内的文件添加到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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.