Please help Ukrainian armed forces! Official Fundraising

OpenFileDialog and SaveFileDialog

1 1 1 1 1 OpenFileDialog and SaveFileDialog5.00Rating 5.00 (1 Vote)

In C#.NET development environment, the common dialog windows for opening and saving files are represented by the OpenFileDialog and SaveFileDialog classes. The classes have much in common, so let's look at them together in this article.

OpenFileDialog and SaveFileDialog share a number of properties in common, among which we can note the following properties:
DefaultExt: sets the default file extension, which is added to the file name if the user has entered a file name without an extension

AddExtension: if true, adds an DefaultExt extension (see above) to the file name if the extension does not exist. The extension is taken from the DefaultExt or Filter property

CheckFileExists: if this property is set to true, then checks for the existence of a file with the specified name and alerts the user if they want to overwrite the file.

CheckPathExists: if true, then checks for the existence of an entire file path with the specified name

FileName: Upon completion, returns the full name of the file selected in the dialog

Filter: Specifies a file filter so that you can filter files by extension in the dialog box. The filter is specified in the following format FileName | * .extension. For example, Text Files (*. Txt) | * .txt. You can specify several filters at once, for this they are separated by a vertical line |. For example, Bitmap files (* .bmp) | * .bmp | Image files (* .jpg) | * .jpg

InitialDirectory: sets the directory that is displayed when the window is first invoked

Title: title of the dialog box

Separately, in the SaveFileDialog class, you can also highlight a couple of properties:

CreatePrompt: if true, if a non-existing file is specified, a message about its creation will be displayed

OverwritePrompt: if true, if an existing file is specified, a message will be displayed stating that the file will be overwritten

To display the created dialog box, call the ShowDialog () method.

Thursday the 21st.