SharePoint Experts, Information Architects, Expert Witness

SICG provides a broad array of business and technology consulting from architecture to design to deployment of global systems with a focus on surfacing data in the enterprise. We focus on the "How", not just the possible. Contact me direct: or call 704-873-8846 x704.

Search This Blog

Monday, November 29, 2010

Troubles using Dialog Boxes in Silverlight

I've often come across this but after working on a long project, often forget the basics - as in using Dialog boxes for File operations. The stanard error is "Dialogs must be user-initiated" which is a little off from the point - you'd expect that a click event could also open a dialog however it is because the threading (context) of the Dialog would be lost in the event.

The solution is simple - simply put all of the Dialog logic in its own method and call the method from the click event:

private void ExportFile_Click(object sender, RoutedEventArgs e)

private void ExportTheFile();
     SaveFileDialog SFD = new SaveFileDialog();
     SFD.DefaultExt = "*.txt";
     SFD.Filter = "Text (*.txt) | *.txt|All files (*.*)|*.*";
     if (SFD.ShowDialog())
            StreamWriter OutStream = new StreamWriter(SFD.OpenFile());

No comments: