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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.