Click here to Skip to main content
15,917,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get the subfolders count of the directory available at server side.

depends on the subfolders names, I need to fill the tree view. so that instead of static display of treeview, I can make it dynamic filling of the treeview.

Help me please.
Posted

Use DirectoryInfo class available in System.IO namespace


DirectoryInfo info = new DirectoryInfo("C:\\MySpace");
            IEnumerable<directoryinfo> var =    info.EnumerateDirectories();</directoryinfo>


var would contain all the information about sub directories
 
Share this answer
 
Here you go... sample code for getting the subfolder count:
C#
//WAY 1
int iCount =0;
DirectoryInfo diSource = new DirectoryInfo(sourceDirectory);
DirectoryInfo[] disSubFolders = diSource.GetDirectories();
iCount = disSubFolders.Length;

//WAY 2
int iCount =0;
DirectoryInfo diSource = new DirectoryInfo(sourceDirectory);
foreach (DirectoryInfo di in diSource) 
{
   iCount ++;   
   //Can do anything else too if needed. 
}
 
Share this answer
 
Hi Thanks for the response, I have developed the same code earlier, the problem I was able to get the root folder of the project, but I am not getting the complete path. How to read the subfolders without complete path of the folder at server side.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900