Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display a list of directories and files 1

Status
Not open for further replies.

vatawna

Programmer
Feb 24, 2004
67
US
Hello,

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.

Thanks,
Mimi
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top