15.12. Save File Dialog Box

A major issue in previous versions of Silverlight was that there was no capability of transferring files to a user. Silverlight 3.0 has a new file save dialog box that allows users to save content to their local machine rather than to isolated storage. This example creates a text file and then gives the user the option to save it:

void cmdSave_Click(object sender, RoutedEventArgs e)
{
    SaveFileDialog SaveDialog = new SaveFileDialog();
    if (SaveDialog.ShowDialog() == true)
    {
        System.IO.Stream fs = null;

        try
        {
            fs = SaveDialog.OpenFile();
            byte[] info =
              (new System.Text.UTF8Encoding(true)).GetBytes("Test text to write to file");
            fs.Write(info, 0, info.Length);
        }
        finally
        {
            fs.Close();
        }
    }
}

15.12.1. Filtering Files in SaveDialog

Files shown in the SaveDialog window can be filtered by type using the Filter and FilterIndex properties. The Filter property allows you to specify a pipe-delimited list of file types and FilterIndex (0 based) sets the default filter to use.

This example shows how to show two filter options with the default filter option set to all files:

SaveDialog.Filter = "Text Files (.txt)|*.txt|All Files|*.*";
//Set default filter to All Files
SaveDialog.FilterIndex = 1;

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.27.141