The direct answer: you cannot, Silverlight SaveFileDialog can be opened only as a direct result of user interaction, for example, pressing a button.
The solution to this problem (where you want to download) is to send XML to the server for storage, say, in a session object or as a file. The answer is some kind of handle that you can use to retrieve XML, such as a GUID.
You can then use standard navigation by placing the GUID in the query string of the URL. The receiving script (ashx in this case) can retrieve the previously hosted XML using the handle specified in the URL.
You will also want to encode the server-side response as follows: -
context.Response.ContentType = imageFactory.ContentType; context.Response.AddHeader("Content-Disposition", "attachment;file=someimage.jpg"); imgStream.WriteTo(context.Response.OutputStream); imgStream.Close();
this will cause the browser to display the "Open or Save" dialog box. Normally, the navigation state of the current window is maintained so that the SL application remains in its current state, but I have not actually tested it.
By the way, donβt notice Response.End (), this is a terrible thing, if you can avoid it, do it.
source share