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();
}
}
}
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.
LikeLike
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!
LikeLike