1
在我的應用程序中,我必須通過http協議從web服務器保存文本文件以及二進制文件。有人能給我任何提示如何繼續?如何將文件保存在web服務器的wp7應用沙箱中?
在我的應用程序中,我必須通過http協議從web服務器保存文本文件以及二進制文件。有人能給我任何提示如何繼續?如何將文件保存在web服務器的wp7應用沙箱中?
您可以下載這些文件並將它們複製到獨立存儲。
事情是這樣的......
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);
}
}
}
感謝ü非常感謝!它工作得很好! – masiboo