private void DownloadFile(string uri, string filename)
{
var wc = new WebClient();
wc.OpenReadAsync(new Uri(uri), filename);
wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);
}
void wc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error != null) return;
var filename = e.UserState.ToString();
var str = e.Result;
using (var myStore = IsolatedStorageFile.GetUserStoreForApplication())
{
if (myStore.FileExists(filename)) myStore.DeleteFile(filename);
var buffer = new byte[1024];
using (var isoStorStr = myStore.OpenFile(filename, FileMode.CreateNew))
{
int bytesRead = 0;
while ((bytesRead = str.Read(buffer, 0, 1024)) > 0)
isoStorStr.Write(buffer, 0, bytesRead);
}
}
}