我正在从 skydrive 文件夹下载图像。下载图像后,我需要将其保存在名为“图片”的文件夹中
但是我怎样才能得到下载文件的名称呢?我尝试了下一个代码,但fs返回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;
}