Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save file with appropriate extension in a Save File prompt

Tags:

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.

like image 661
novacara Avatar asked Jul 31 '09 15:07

novacara


People also ask

What is the extension to save the file?

Files with the . save extension are temporary files containing data associated with text documents created using the Unix Nano text editing application.

How we can save a file using Save File dialog control?

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.


2 Answers

SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "Data Files (*.dat)|*.dat"; dlg.DefaultExt = "dat"; dlg.AddExtension = true; 
like image 127
Francis B. Avatar answered Sep 18 '22 21:09

Francis B.


The AddExtension and DefaultExt properties. For example:

sfdialog.DefaultExt = "dat"; sfdialog.AddExtension = true; 
like image 40
John Calsbeek Avatar answered Sep 20 '22 21:09

John Calsbeek