Wednesday, 11 September 2013

Save File Dialog , restrict name

Save File Dialog , restrict name

my program has a save file option which is shown below :
//Browse for file
SaveFileDialog ofd = new SaveFileDialog();
ofd.Filter = "CSV|*.csv";
ofd.DefaultExt = ".csv";
DialogResult result = ofd.ShowDialog();
string converted = result.ToString();
if (converted == "OK")
{
Master_Inventory_Export_savePath.Text = ofd.FileName;
}
if I write the file name as "example" it saves correctly as a .csv however
if I set the name as "example.txt" it saves as a text file , I've looked
on msdn etc but even setting the default extension doesn't prevent this ,
any ideas on how to only allow files of .csv to be saved ?

No comments:

Post a Comment