Home

The Save Dialog Box

 

Description

Most of the applications allow users to open or display an empty document. This indicates that such an application expects the user to create a document. Once a document has been created, a user would usually want to store its contents on a medium (hard drive, floppy disk, etc). Microsoft Windows provides a common dialog box for this purpose: The Save As dialog box:

The Save As Dialog Box

The primary role of the Save As dialog box is to allow users to store a file on the hard drive of the computer, on a portable medium such as a floppy disk, or on a network drive. To make this efficient and complete, the user must supply two valuable pieces of information: the location and the name of the file. The location of a file is also known as its path.

The name of a file follows the directives of the operating system. On MS DOS and Windows 3.X, it had to be in an 8.3 format. The actual name had to have a maximum of 8 characters with restrictions on the characters that could be used. The user also had to specify three characters after a period. The three characters, known as the file extension, were used by the operating system to classify the file. That was all necessary for those 8-bit and 16-bit operating systems.

Various rules have changed. For example, the names of folders and files on Microsoft Windows >= 95 can have up to 255 characters. The extension of the file is mostly left to the judgment of the programmer but most files are still using extensions. Applications can also be configured to save different types of files; that is, files with different extensions.

To use the Save As dialog box, users usually click an item under the File menu. Here is how it works for most regular applications. The user creates a new document. If the user wants to save the file, he or she can click File -> Save. If the document was not previously saved, the application would call the Save As dialog box. If a document is displaying, whether it was saved previously or not, the user can also click File -> Save As... which also would call the Save As dialog box.

Two objects are particularly important on the Save As dialog box: The Save In combo box and the File Name text box or combo box (the File Name box is made of a combo box to make it user-friendly but over all, users hardly use the list side of this combo box). Since Windows 95, the user does not have to specify an extension if the programmer makes it easy. To help with this, the Save As dialog box is equipped with a Save As Type combo box. This combo box allows the user to select one of the extensions. The available extensions have to be created by the programmer so the user can select from a preset list. If the programmer neglects this, the user would have no extension to select from. Although the file can still be saved, the operating system would not associate it with a known type of file. Therefore, if you specify a series of extensions, the user can select one of these and, in the File Name box, he or she can simply type a name for the file.

If the user does not specify an extension, the operating system would associate the extension of the Save As Type combo box. Users of regular commercial applications, such as word processors, spreadsheet programs, or graphical applications, etc, are usually trained not to care about the extensions and let the application deal with that detail. In some other circumstances, the users must pay close attention to the extension they give a file. This is common on web development or graphics design because various file extensions are supported and overall produce the same end result.

After working on a Save As dialog box, users can click Save or press Enter, which would validate their entry. To change their mind, regardless of what they did on the Save As dialog box, users can click Cancel or press Esc, which would dismiss the dialog box and ignore what they did (in reality, some actions cannot be ignored, such as creating a new file or folder inside of the Save As dialog box, deleting, cutting, or pasting files, etc; but if the user clicked Cancel or pressed Esc, the new file would not be saved).

Save As Dialog Box Creation

To make a Save As dialog box available to your application, on the Toolbox, you can click the SaveFileDialog button SaveFileDialog Control and click the form. To programmatically provide this dialog box, you can declare a SaveFileDialog variable and initialize it using the class's default constructor as follows:

using System;
using System.Windows.Forms;

public class Exercise : Form
{
    private SaveFileDialog sfd;

    public Exercise()
    {
	InitializeComponent();
    }

    void InitializeComponent()
    {
        sfd = new SaveFileDialog();
    }
}

public class Program
{
    public static int Main()
    {
        Application.Run(new Exercise());

        return 0;
    }
}

The SaveFileDialog class inherits from the FileDialog class from which it gets most of its characteristics and behaviors.

 

Home Copyright © 2007 FunctionX, Inc. Next