I am downloading images from skydrive folder. When the image is downloaded , I need to save it in a folder called ‘pictures’
But how I can get the name of the file downloaded? I tried the next code but fs returns null
private void download()
{
if (ControlBackup_ID != null)
{
foreach (string it in contenidoSkyPic)
{
//MessageBox.Show (it);
infoTextBlock3.Text = "Downloading backup pictures..wait...";
client.DownloadAsync(it + "/content");
client.DownloadCompleted += new EventHandler<LiveDownloadCompletedEventArgs>(client_DownloadCompleted);
}
}
else
MessageBox.Show("Backup file of pictures doesn't exist!", "Error", MessageBoxButton.OK);
}
void client_DownloadCompleted(object sender, LiveDownloadCompletedEventArgs e)
{
if (e.Error == null)
{
Stream stream = e.Result; //Need to write this into IS
FileStream fs = stream as FileStream;
if (fs != null)
{
try
{
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("pictures\\" + fs.Name, FileMode.Create))
{
stream.CopyTo(fileStream);
cantImatges_progreso_down += 1;
}
}
}
catch { }
if (cantImatges_progreso_down == contenidoSkyPic.Count())
{
infoTextBlock3.Text = "Restore pictures completed!";
}
}
}
else
{
// process error
MessageBox.Show("Restore pictures failed.", "Failure", MessageBoxButton.OK);
}
client.DownloadCompleted -= client_DownloadCompleted;
}
Finally, I have found this solution. I have seen that I can use “userstate” to pass filename
Solution:
When i scann skydrive folder, now I store ID and filename:
Then, “Download” will be:
when client_DownloadCompleted is called whenever a download completes and I can get the name of each file: