[英]Saving Files in silverlight and asynchronous call backs
在Silverlight中,您必须使用“保存文件”对话框来保存文件。
您只能通过用户事件(也就是单击按钮)打开此对话框
我正在从Web服务调用异步返回文件的数据
如何将其保存到文件?
如果我在服务呼叫之前询问他们,则数据返回后我将无法使用该流。
如果在无法打开保存文件对话框后问他们。
这有点鸡和鸡蛋的情况。
谢谢。
更新
我希望能够将用户计算机保存在他们未指定Silverlight孤立存储的位置。
从用户事件中打开一个SaveFileDialog
,然后保留对该对话框的引用。 进行Web服务调用,然后在此调用的处理程序中,调用SaveFileDialog
上的OpenFile()
方法 。 使用此方法返回的流来写入文件。
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...
}
如果您想要使用该技术的更详细的示例,请参见此处 。
如果我对您的问题正确无误,请提出以下解决方案。
当然,会有一个按钮将打开保存按钮。 但是该按钮将在服务呼叫完成后启用。 您可以将该数据临时保存到隔离的存储中。 现在启用按钮。 点击打开保存诊断框后,
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();
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.