I am developing exporting data in xpdl format. There are 2 options - version 2.1 and 2.2. I am using SaveFileDialog, but how can I distinguish between those 2 options?
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "xpdl 2.1|*.xpdl|xpdl 2.2|*.xpdl";
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
//how can I check, which format is selected?
}
Split the Filter list. Then look at the FilterIndex.
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "xpdl 2.1|*.xpdl|xpdl 2.2|*.xpdl";
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string[] filterstring = saveFilaDialog.Filter.Split('|');
MessageBox.Show(filterstring[(saveFilaDialog.FilterIndex - 1) * 2]);
}
You can get or set selected filter for dialogs by checking FilterIndex property. And as stated in msdn:
The index value of the first filter entry is 1.
So for your task it would be:
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "xpdl 2.1|*.xpdl|xpdl 2.2|*.xpdl";
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
switch (dlg.FilterIndex)
{
case 1:
//selected xpdl 2.1
break;
case 2:
//selected xpdl 2.2
break;
}
}
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