In my application I use a SaveFileDialog to pop up a Save As window. I have restricted in the file type section the file to be saved as .dat with the following code.
sfdialog.Filter = "Data Files (*.dat*)|*.dat*";
What I want to know how to do is make it automatically save with the .dat extension. Currently it just saves with no extension unless I specifically save it as filename.dat.
Files with the . save extension are temporary files containing data associated with text documents created using the Unix Nano text editing application.
To save a file using the SaveFileDialog component. Display the Save File dialog box and call a method to save the file selected by the user. Use the SaveFileDialog component's OpenFile method to save the file. This method gives you a Stream object you can write to.
SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "Data Files (*.dat)|*.dat"; dlg.DefaultExt = "dat"; dlg.AddExtension = true;
The AddExtension and DefaultExt properties. For example:
sfdialog.DefaultExt = "dat"; sfdialog.AddExtension = true;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With