Does anybody know how to populate the combo box control with directories and files starting from the top level "My Computer"? In other words, the combo box control actually shows a tree of directories and files when it is dropped-down.
You have System.Management workspace to accompplish this task.
To get the Desktop and the logical drivers:
System.Management.ManagementObject mgtObject;
System.Management.ManagementObjectSearcher oSearch=new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk");
Now loop each drive held in the oSearcher object and place each drive in mgtObject:
foreach mgtObject in oSearcher.Get()
{
int driverImage=-1;
string sDriveLetter = mgtObject.Properties("DeviceID").Value;
string sDriveDesc = sDriveLetter + mgtObject.Propoerties("Description").Value;
string sVolumeName = mgtObject.Properties("VolumeName").Value;
//get the image for disk
switch(driverImage=Convert.ToInt16(mgtObject.Properties"DriveType").Value)
{
case 6: // Unknown
case 3: // Compact disk
case 4: // Network disk
case 2: // Local disk
driverImage=2;
case 1: // Removable
case 6: // No root directory
case 0: // RAM disk
}
// Check network connection
// if image drive is 4 and mgtObject.Properties("Size").Value is null then
driverImage =5 (Network disconnected)
}
Retrive the images of each drive using Bitmap object and draw the tree in the combobox with these drivers elements(letter, image and description):
+image Desktop
+ image C:\Local Disk Doppo.
+ image D:\ DVD/CD RW-Drive
+ image E:\ Removable Disk
Now iterate through each availabale drive and retrive a list of folders and so on files using System.IO.Directory.
For full information see Windows Management Instrumentation (WMI).
obislavu
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.