SaveFileDialog.FilterIndex Always Returns 1 (Or Value Set Prior to ShowDialog Call) RRS feed

  • Question

  • Found a difference between Silverlight 3 Beta 1 and Silverlight 3 RTM.  Specifically, SaveFileDialog.FilterIndex will always return 1, or the value specifically set for FilterIndex.  It does not update to refelect the filter chosen by the user.
    1    private void OnSaveClick(object sender, RoutedEventArgs e)
    2    {
    3        string filter = "JPEG Files (*.jpg)|*.jpg|TIFF Files (*.tif)|*.tif|Bitmap Files (*.bmp)|*.bmp|All Files (*.*)|*.*";
    5        SaveFileDialog dialog = new SaveFileDialog();
    6        dialog.Filter = filter;
    8        bool? result = dialog.ShowDialog();
    9        if (true == result)
    10       {
    11           // FilterIndex is always 1 (default) or the value explicitly set 
    12           // if you set FilterIndex before calling ShowDialog
    13           MessageBox.Show("Filter Index = " + dialog.FilterIndex.ToString());
    14       }
    15   }

    I checked the OpenFileDialog, and it behaves as expected.  Silverlight 3 RTM, Windows 7 Professional RTM.  Also, tested and verified bug on Visa Professional SP2.

    Has this been previously reported?  Expected? 

    Friday, August 14, 2009 10:35 AM


  • Thanks for reproting this bug. It will be fixed in the next version.

    Monday, October 12, 2009 12:26 PM

All replies

  • Not sure of the protocol, but I'd appreciate any feedback as to whether this is truly a defect or not.  Looking at the code for SaveFileDialog in Reflector, the value returned by FilterIndex is set properly, so my guess is the defect occurs in the native stuff underneath.

    Confirmation possible?  Thanks! 

    Tuesday, August 18, 2009 5:30 PM
  • I have definitely hit this bug.  When running on the local VS hosted server, it behaves as expected.  However, when deployed to the web it always returns the intially set FilterIndex.

     Some help from the Silverlight team would be appreciated... this renders the File Type useless!

    Thursday, October 8, 2009 2:37 PM
  • FYI, this also happens when running Silverlight 3 on Azure, the latest CTP.  Really causing a big headache.

    Monday, October 12, 2009 11:29 AM
  • When you use OpenFileDialog or SaveFileDialog, the purpose of the filter is to show only a selected subset of files.  However, in either case the user can arbitrarily save to different file extensions by typing the full name.  So whatever the selected file extension should not be interpreted too much, and IMO you should take any interpretation from the actual file extension.
    Monday, October 12, 2009 12:14 PM
  • Thanks for reproting this bug. It will be fixed in the next version.

    Monday, October 12, 2009 12:26 PM
  • I'm not sure that I agree with that reasoning.  If the user typed in myfile.sdjkhfskj, which file format should I use? 

    I'll also cite an example within Windows... suppose I create a drawing in Paint and select 24-bit Bitmap as my file type, but type in myPicture.gif as the filename.  This image will be saved as myPicture.gif, and by default will open in Internet Explorer.  However, the picture won't be displayed, because the encoding isn't recognized.  Changing the extension to .bmp makes the file readable again, this time opening in Paint.

     The point of this example, is that just because I saved the file with a .gif extension, Paint did not encode it as such.

    Monday, October 12, 2009 12:27 PM
  • This scenario is exactly what I was using the FilterIndex property for.  Looking at extensions for pretty much anything can cause problems, particularly in imaging, because the encoded data can at times have nothing to do with the file extension.

    But, it looks like we have an acknowledgment of the defect now, so I guess we're answered for now...

    Monday, October 12, 2009 12:36 PM
  • Is this bug fixed in Silverlight 4?  It doesnt appear so but a dev in this thread said it would be.  


    I am on Silverlight 4.0.50524.0 and get the same results whether on local web or published to internet, the dialog always returns a filterindex of 1.  


    Besides programmatically having the user select a file format before starting the dialog, anyone else found a way around this?



    Sunday, August 22, 2010 6:28 AM
  • I've hit the same issue, but I'm thinking it might not be a Silverlight (5.1.10411.0) bug. When I'm testing the app from the local iisexpress, everything works fine. When I'm testing the app deployed on a remote IIS in IE9 the dialog always returns the initial FilterIndex setting regardless of user choice. However in Firefox (13.0.1) everything works fine in both cases.
    Friday, November 23, 2012 3:13 PM