5.18. Show the Common File Dialog Boxes

Problem

You need to show the standard Windows dialog boxes for opening and saving files and for selecting a folder.

Solution

Use the OpenFileDialog, SaveFileDialog, and FolderBrowserDialog classes in the System.Windows. Forms namespace. Call the ShowDialog method to display the dialog box, examine the return value to determine whether the user clicked Open or Cancel, and retrieve the selection from the FileName or SelectedPath property.

How It Works

The .NET Framework provides objects that wrap many of the standard Windows dialog boxes, including those used for saving and selecting files and directories. Each dialog box is appropriately formatted for the current operating system. The dialog box classes ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.