Explorer-Style Application Sample

This sample contains two forms that are both Explorer-like: DirectoryScanner and ExplorerStyleViewer.

Security Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To run this sample

  1. Click the Download Sample button on this page. In the File Download dialog box, click Open.

  2. Save the files to your computer.

  3. On the File menu in Visual Studio, point to Open, and then click Project/Solution.

  4. Browse to the folder where you saved the files and select the solution file. This opens the solution in Visual Studio.

  5. Press F5.

Demonstrates

This sample contains two forms with an Explorer-like interface: a directory scanner and an Explorer-style viewer. The files that support the two forms are contained in separate folders of the project.

  • DirectoryScanner   This is a simple application that scans all directories and sub-directories in either all logical drives or a user-selected starting directory. The list of drives is obtained using the Directory.GetLogicalDrives method. A TreeView control displays the directory structure reflecting the latest scan. Directories are colored green, yellow, or red based on their total size inclusive of all sub-directories and files. The Directory.GetFiles method is used to retrieve the list of files, and the FileInfo class is used to get the file size.

  • ExplorerStyleViewer   This is a simpler version of the Windows Explorer application. The ExplorerStyleViewer displays more file information than DirectoryScanner by using the FileSystemInfo.Attributes property. It demonstrates how to associate icons with file types using the TreeView.ImageList property. It allows the user to run an application associated with the file type (if an association exists) by double-clicking the file (just like in Windows Explorer). Applications are started using the Process.Startmethod.