Skip to main content

Using Open File and Save File dialog boxes in .NET

  • February 15, 2013
  • 0 replies
  • 0 views

Problem:

This pertains to Net Express 5.0 with Visual Studio .NET 2005:

Using Open File and Save File dialog boxes in .NET.

The 2 WinForms classes used to create dialog boxes for Open and Save are System.Windows.Forms.OpenFileDialog and System.Windows.Forms.SaveFileDialog. For more details about the properties and methods of these classes, do an index search through the Visual Studio 2005 Help or go to http://msdn.microsoft.com/library where you can search the classes by their full names (namespace and class).

Resolution:

To use an Open File dialog box, double-click OpenFileDialog from the Dialogs section of the Toolbox in the Visual Studio .NET 2005 IDE. An icon of the object will not appear on your form, but you will see it below the form on the Form Design window. Click on it to see and set it's properties  in the Properties window.

The OpenFileDialog object has a ShowDialog method which makes it appear to the user. If a single file is chosen by the user, the FileName property contains the name of that file. If the Multiselect property is set to true and the user has selected multiple files, then the FileNames property contains an array of names.

There are many other properties which you can see and set with the Properties window.   

The SaveFileDialog object has similar properties and methods.

Please see the source code in the attached demo for details.

   

Old KB# 4317