1

I'm having 10 image urls. I want to download those images and htmls to local folder and replace the image paths in corresponding image source of htmls. How to download 10 images from urls. below code for single image download.

var webClient = new WebClient();
webClient.OpenReadCompleted += WebClientOpenReadCompleted;
webClient.OpenReadAsync(new Uri(webimages["image url"], UriKind.Absolute));

void WebClientOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
    const string tempJpeg = "TempJPEG";
    var streamResourceInfo = new StreamResourceInfo(e.Result, null);

    var userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication();
    if (userStoreForApplication.FileExists(tempJpeg))
    {
       // userStoreForApplication.DeleteFile(tempJpeg);
        MessageBox.Show("Image Already Exists");
    }

    var isolatedStorageFileStream = userStoreForApplication.CreateFile(tempJpeg);

    var bitmapImage = new BitmapImage { CreateOptions = BitmapCreateOptions.None };
    bitmapImage.SetSource(streamResourceInfo.Stream);

    var writeableBitmap = new WriteableBitmap(bitmapImage);
    writeableBitmap.SaveJpeg(isolatedStorageFileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 85);

    isolatedStorageFileStream.Close();
    isolatedStorageFileStream = userStoreForApplication.OpenFile(tempJpeg, FileMode.Open, FileAccess.Read);

    // Save the image to the camera roll or saved pictures album.
    var mediaLibrary = new MediaLibrary();

    // Save the image to the saved pictures album.
    mediaLibrary.SavePicture(string.Format("SavedPicture{0}.jpg", DateTime.Now), isolatedStorageFileStream);

    isolatedStorageFileStream.Close();
}
1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.