我有代碼的所有文件夾中查找和顯示名稱在rootfolder所有子文件夾名稱:如何顯示文件夾名稱,並在下拉列表
private string[] GetFolderNames(string virtualDirPath)
{
string[] Directories;
if (Directory.Exists(virtualDirPath))
{
Directories = Directory.GetDirectories(virtualDirPath);
for (int i = 0; i < Directories.Length; i++)
{
Directories[i] = MapUrl(Directories[i]);//map path to the folder
}
return Directories;
}
else
{
return null;
}
}
和代碼數據綁定到下拉列表:
string[] folders = GetFolderNames(RootPath);
if (folders != null)
{
dropDownListFolders.DataSource = folders;
dropDownListFolders.DataBind();
}
else
{
dropDownListFolders.Items.Insert(0, "No folders available..");
}
如上面的代碼,Dropdownlist顯示Rootfolder
中的所有文件夾名稱,路徑= virtualDirPath
;
但是我想知道是否在每個子文件夾中仍然有一些子文件夾,並且在每個子文件夾中都有更多的子文件夾等等,以便我如何獲取子文件夾的所有名稱。
儘量在第一個環內製作更多的for
環,但它確實讓我感到困惑。看來這不是好的方法。
我需要Dropdownlist顯示根文件夾中的所有子文件夾名稱,子文件夾的子文件夾和子文件夾的子文件...。幫幫我!我需要你的意見,找到一個更好的方法來。
這麼酷,它真的幫助我。非常感謝。 –
歡迎您... – super