gpt4 book ai didi

c# - 在 silverlight 和异步回调中保存文件

转载 作者:太空宇宙 更新时间:2023-11-03 14:25:54 24 4
gpt4 key购买 nike

在 Silverlight 中,您必须使用保存文件对话框保存文件。

您只能通过用户事件(即单击按钮)打开此对话框

我正在异步地从 Web 服务调用返回一个文件的数据

如何将其保存到文件?

如果我在服务调用之前询问他们,我将无法在数据返回后使用流。

如果我在无法打开保存文件对话框后询问他们。

这是先有鸡还是先有蛋的情况。

谢谢。

更新

我希望能够将用户计算机保存在他们指定的位置而不是 silverlight 隔离存储。

最佳答案

从用户事件中打开一个SaveFileDialog,然后保留对该对话框的引用。进行 Web 服务调用,然后在该调用的处理程序中调用 OpenFile() methodSaveFileDialog 上。使用此方法返回的流写入您的文件。

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...
}

如果您想要使用相同技术的更详细示例,请参阅 here .

关于c# - 在 silverlight 和异步回调中保存文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4024267/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com