Reputation: 1364
In Silverlight you have to save a file using the save file dialog.
You can only open this dialog from a user event aka a button click
I’m returning the data of a file from a web service call asynchronously
How do i save this to file?
If i ask them before the service call i can’t use the stream after the data comes back.
If i ask them after i can’t open the save file dialogue.
It’s a bit of chicken and the egg situation.
Thanks.
update
i want to be able to save the users computer where they spectifiy not the silverlight isolated storage.
Upvotes: 2
Views: 1807
Reputation: 112875
Open a SaveFileDialog
from a user event, then keep a reference to this dialog around. Make your web service call, then in the handler for this call, call the OpenFile()
method on the SaveFileDialog
. Use the stream returned by this method to write to your file.
private SaveFileDialog _mySaveDialog;
private void Button_Click(object sender, EventArgs e)
{
_mySaveDialog = new SaveFileDialog();
// Configure the dialog and show it here...
}
// call this method from the handler for your web service call
private void Save(string toSave)
{
Stream fileStream = _mySaveDialog.OpenFile();
// Write to the file here...
}
If you'd like an even more detailed example that uses this same technique, see here.
Upvotes: 2
Reputation:
if i get your question correct, here is proposed solution.
off course there would be a button which will open the save button. but that button would be enabled when the service call completes. you can save that data temporary into isolated storage. Enable the button now. on clicking that open the save diag box,
public static void SaveLog(string data)
{
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(fileName, FileMode.Append, FileAccess.Write, isf))
{
using (StreamWriter sw = new StreamWriter(isfs))
{
try
{
sw.Write(data);
}
finally
{
sw.Close();
}
}
}
}
}
Upvotes: 0