在Silverlight和异步回调保存文件 [英] Saving Files in silverlight and asynchronous call backs
问题描述
在Silverlight中,你必须使用保存文件对话框,保存文件。
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
我从Web服务调用返回的文件的数据不同步
I’m returning the data of a file from a web service call asynchronously
我如何保存这文件?
如果我问他们的服务电话之前,我不能使用流后的数据回来。
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.
感谢。
更新
我希望能够保存用户的电脑,他们spectifiy不是Silverlight的隔离存放。
i want to be able to save the users computer where they spectifiy not the silverlight isolated storage.
推荐答案
从用户事件打开 SaveFileDialog
,然后继续引用这个对话框各地。让您的Web服务调用,那么在处理这个调用,调用<一href="http://msdn.microsoft.com/en-us/library/system.windows.controls.savefiledialog.openfile%28v=VS.95%29.aspx"相对=nofollow> 打开文件()
方法上的 SaveFileDialog
。使用此方法返回的流写入到您的文件。
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...
}
如果你想使用同样的技术更详细的例子,请参阅<一href="http://www.silverlightshow.net/items/Using-the-SaveFileDialog-in-Silverlight-3.aspxhttp://www.silverlightshow.net/items/Using-the-SaveFileDialog-in-Silverlight-3.aspx"相对=nofollow>这里。
If you'd like an even more detailed example that uses this same technique, see here.
这篇关于在Silverlight和异步回调保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!