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
. 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);
精彩评论