![]() ![]() ![]() The initial directory used by the SaveFileDialog is decided by Windows, but by using the InitialDirectory property, you can override it. This also indicates to the user which file formats your application supports, which is of course important. With that in place, you can write filenames without specifying the extension - it will be taken from the selected file type in the filter combo box With a filter like the above, the resulting SaveFileDialog will look like this instead: saveFileDialog.Filter = "Text file (*.txt)|*.txt|C# file (*.cs)|*.cs" įor more details about the format of the Filter property, please see the previous article on the OpenFileDialog, where it's explained in details. Like for the OpenFileDialog, this box is controlled through the Filter property, and it's also used in the exact same way. txt extension to my desired filename, mainly because the "Save as type" combo box is empty. If you click the save button, you should see a dialog like this, depending on the version of Windows you're using: FilterĪs you can see from the first example, I manually added a. Returns true, we use the FileName property (which will contain the selected path as well as the user entered file name) as the path to SaveFileDialog saveFileDialog = new SaveFileDialog() įile.WriteAllText(saveFileDialog.FileName, txtEditor.Text) Īs you can see, it's mostly about instantiating the SaveFileDialog and then calling the ShowDialog() method. Private void btnSaveFile_Click(object sender, RoutedEventArgs e) Public partial class SaveFileDialogSample : Window To kick things off, let's begin with a very simple example on using the SaveFileDialog: Meaning that your users will see roughly the same dialog whether they initiate it in your application or e.g. Just like the OpenFileDialog, the SaveFileDialog is a wrapper around a common Windows dialog, Used in the previous article, with a few subtle differences. It works and looks much like the OpenFileDialog which we ![]() The SaveFileDialog will help you select a location and a filename when you wish to save a file. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |