[英]how to save file in wp7's app sandbox from webserver?
在我的应用程序中,我必须通过 http 协议从网络服务器保存文本文件和二进制文件。 有人可以给我任何提示如何进行吗?
您可以下载文件并将它们复制到独立存储。
像这样的东西...
private void DownloadFiles()
{
var wc = new WebClient();
wc.OpenReadCompleted += WcOpenReadCompleted;
wc.OpenReadAsync(new Uri("http://myserver/myfile.file", UriKind.Absolute));
}
public static void CopyStream(Stream input, Stream output)
{
var buffer = new byte[32768];
while (true)
{
int read = input.Read(buffer, 0, buffer.Length);
if (read <= 0)
return;
output.Write(buffer, 0, read);
}
}
private static void WcOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
using (IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication())
{
var isolatedStorageFileStream = userStoreForApplication.CreateFile("mylocalfilename");
using (isolatedStorageFileStream)
{
CopyStream(e.Result, isolatedStorageFileStream);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.