Home > WPF > Open a ‘File Save Dialog’ window in Silverlight – During Asynchronous Call

Open a ‘File Save Dialog’ window in Silverlight – During Asynchronous Call


Generally its not possible to open a SaveFileDialog window in Synchronous complete method like,

Wrong Method :

private void Method(Object param)
{
Client consoleClient = new Client(“”);
consoleClient.XXXCompleted+=new EventHandler<XXXCompletedEventArgs>(Method_Completed);
XXXRequest request = new XXXRequest();
request.p_Parameters = param;
consoleClient.XXXAsync(request);
}

void Method_Completed(object sender, XXXCompletedEventArgs e)
{
var result = (YYY)e.Result.XXXResult;
UIThread.Run(delegate() {
SaveFileDialog dlg = new SaveFileDialog();      // This will throw a Exception
dlg.DefaultExt = “.zip”;                        // Default file extension
dlg.Filter = “Zip Archive (.zip)|*.zip”;       // Filter files by extension
if (dlg.ShowDialog() == true)
{

}
}
}

Right Method:

private void Method(Object param)
{
Client consoleClient = new Client(“”);
consoleClient.XXXCompleted+=new EventHandler<XXXCompletedEventArgs>(Method_Completed);
XXXRequest request = new XXXRequest();
request.p_Parameters = param;
consoleClient.XXXAsync(request);
}

void Method_Completed(object sender, XXXCompletedEventArgs e)
{
var result = (YYY)e.Result.XXXResult;
ChildWindowDlg _confirmationWnd = new ChildWindowDlg ();
_confirmationWnd.Show();
}

and inside that ChildWindowDlg  class create a method and call SaveDialog window, like

void Save_ButtonClick(object sender, routedEventArg e)
{
SaveFileDialog dlg = new SaveFileDialog();
dlg.DefaultExt = “.zip”;
dlg.Filter = “Zip Archive (.zip)|*.zip”;
if (dlg.ShowDialog() == true)
{
using(Stream s = (Stream)dlg.OpenFile())
{
s.Write(data, index, length);
s.Close();
}
}
}

Advertisements
Categories: WPF Tags:
  1. May 24, 2013 at 5:01 AM

    Ahaa, its good conversation about this paragraph at this place at this webpage,
    I have read all that, so now me also commenting at this place.

    Like

  2. May 25, 2013 at 9:47 AM

    It’s a pity you don’t have a donate button! I’d without a doubt donate to this superb blog! I guess for now i’ll settle for bookmarking and adding your RSS feed to my Google account.
    I look forward to fresh updates and will talk about this website with my Facebook
    group. Chat soon!

    Like

  1. July 11, 2017 at 1:16 AM

Thanks for your comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: