[英]how to save file in wp7's app sandbox from webserver?
In my application I have to save text file as well as binary files from a webserver by http protocol.在我的应用程序中,我必须通过 http 协议从网络服务器保存文本文件和二进制文件。 Could somebody give me any hints how to proceed?有人可以给我任何提示如何进行吗?
You could download the files and copy them to Isolated Storage.您可以下载文件并将它们复制到独立存储。
Something like this...像这样的东西...
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.