Reputation: 1213
We want to save to files using .NET's System.Windows.Forms.SaveFileDialog.
We have multiple file formats that use the same file extension (similar as in Excel where you also have two .CSV-formats (MS-DOS, and Macintosh)).
Does anyone know how we could get the exact file format the user selected and not only the file name with the file extension since they would be identical. Of course without having to re-implement the dialog... :-)
Cheers!
Upvotes: 1
Views: 1852
Reputation: 11606
You can use the FilterIndex
-Property of the SaveFileDialog
to determinate which FileType the user has choosen.
SaveFileDialog oDialog = new SaveFileDialog();
oDialog.Filter = "CSV-File (Macintosh) (*.csv)|*.csv|CSV-File (MS-DOS) (*.csv)|*.csv";
oDialog.FilterIndex = 1;
if (oDialog.ShowDialog() == DialogResult.OK)
{
switch (oDialog.FilterIndex)
{
case 1:
// Handle CSV (Macintosh)
break;
case 2:
// Handle CSV (MS-DOS)
break;
}
}
Upvotes: 3