Share via


Explorer-Style Application Sample

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

To get samples and instructions for installing them

  • Do one or more of the following:

    • On the Help menu, click Samples.

      The Readme displays information about samples.

    • Visit the Visual Studio 2008 Samples Web site. The most recent versions of samples are available there.

    • Locate samples on the computer on which Visual Studio is installed. By default, samples and a Readme file are installed in drive:\Program Files\Microsoft Visual Studio 9.0\Samples\lcid. For Express editions of Visual Studio, all samples are located online.

For more information, see Visual Studio Samples.

Security noteSecurity Note:

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To run this sample

  • 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 by using the Directory.GetLogicalDrives method. A tree view 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 receive 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 by using the TreeView.ImageList property. It enables 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 by using the Process.Start method.

See Also

Reference

Directory

FileInfo

TreeView.ImageList

ListView

TreeView

Other Resources

ListView Control (Windows Forms)

TreeView Control (Windows Forms)