How to insure file extension on new file.


G

Guest

HI,
I'm using saveFileDialog to get or make a file to save my stirngs to.

saveFileDialog1.Filter = "txt files (*.txt)|*.txt" ; //display dialog
saveFileDialog1.FilterIndex = 2 ;
saveFileDialog1.RestoreDirectory = true ;
DialogResult result2 = saveFileDialog1.ShowDialog();

This displays only txt files.
If the user selects an existing file all goes well.
The problem comes in when the user types in a file name and hits save. Then
the file that gets saved has no extension.
I have the AddExtension in properties set to true and the DefaultExt as txt.
Still no file extension.

What am I doing wrong?

TIA

Bill
 
Ad

Advertisements

O

Otis Mukinfus

HI,
I'm using saveFileDialog to get or make a file to save my stirngs to.

saveFileDialog1.Filter = "txt files (*.txt)|*.txt" ; //display dialog
saveFileDialog1.FilterIndex = 2 ;
saveFileDialog1.RestoreDirectory = true ;
DialogResult result2 = saveFileDialog1.ShowDialog();

This displays only txt files.
If the user selects an existing file all goes well.
The problem comes in when the user types in a file name and hits save. Then
the file that gets saved has no extension.
I have the AddExtension in properties set to true and the DefaultExt as txt.
Still no file extension.

What am I doing wrong?

TIA

Bill

This is an odd quirk of the OpenFileDialog and I suspect it's the same in the
SaveFileDialog. You must have CheckFileExists set to false or the AddExtension
property setting has no effect. In fact you cannot depend on the default
setting to work (the one in the properties). I found that you must set it in
code before it will work.


Otis Mukinfus
http://www.otismukinfus.com
 
Ad

Advertisements

G

Guest

Ah yes,

Not only had to spell things out in code,
but had to clear the defaultExt field in props.

Thanks!

BTW:
Where can I find the FilterIndex options and what the numbers stand for?
They don't seem to make any difference with saveFIleDialog.
Have searched the C# site and NG's with no results.

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top