A quick look at Silverlight 3: Save File Dialog

Silverlight 3 gets a Save File Dialog. Anyone who’s used Silverlight 2 and its Open File Dialog will feel instantly at home as in;

SaveFileDialog sfd = new SaveFileDialog()
      {
        DefaultExt = "txt",
        Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*",
        FilterIndex = 1
      };
      if (sfd.ShowDialog() == true)
      {
        // User selected item. Only property we can get to is.
        using (Stream stream = sfd.OpenFile())
        {
          stream.Close();
        }
      }

As with the Open File Dialog, the dialog has to be raised in response to a direct user interaction like clicking on a button – it can’t be raised by a (potentially malicious) piece of code.

Similarly, the only thing you can do with the dialog is to call the OpenFile() method and that gives you no details about the user’s machine or their file system but simply a Stream that you can write into and close off.

So…pretty simple stuff to use but great in terms of the number of different Silverlight Applications that this will enable 🙂

This is one of a series of posts taking a quick look at Silverlight 3 – expect them to be a little “rough and ready” and that they’ll get expanded on as I’ve had more time to work with Silverlight 3.