[英]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.