title: Download and save a picture from a url Universal windows app
body: <p>I am using the below code to downlaod the picture form a remote url and save to Local storage folder </p>
  
  <pre><code>        try
          {
              var rootFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync( "MyAppName\\CoverPics", CreationCollisionOption.OpenIfExists);
  
              var coverpic_file = await rootFolder.CreateFileAsync(filename, CreationCollisionOption.FailIfExists);
              try
              {
                  var httpWebRequest = HttpWebRequest.CreateHttp(coverUrl);
                  HttpWebResponse response = (HttpWebResponse)await httpWebRequest.GetResponseAsync();
                  Stream resStream = response.GetResponseStream();
                  using (var stream = await coverpic_file.OpenAsync(FileAccessMode.ReadWrite))
                  {
                      await resStream.CopyToAsync(stream.AsStreamForWrite());
                  }
                  response.Dispose();
              }
              catch //any exceptions happend while saving the picture
              {
                  saved = false;
              }
          }
          catch
          {
              //https://msdn.microsoft.com/en-us/library/windows/apps/br227250.aspx 
              //Raise an exception if file already present 
              saved = true;
          }
  </code></pre>
  
  <p>This code is working for me in most of the cases , but i noticed that for few pictures the image is not downloading completely.</p>
  
  <p>I am callling this function in an async block for more tahn 100 images in a single go inside the foreach loop and in the end few of them are failed downloads </p>
  
  <p>[ Either i can see some invalid file is getting created </p>
  
  <p>or part of image only in downloading and rest of the area i can see a black colour block [ looks like image is corrupted].</p>
  
  <p>Size of all images is less than 1 MB only</p>
  
  <p>Can some one help me to optimize this code or point out the mistake in code so i can able to download all the images completely</p>