title: Download file with progress bar in Xamarin Forms
body: <p>I am trying to make a download page in Xamarin Forms (PCL, so WebClient is not usable) with a Download progress bar. I have used the following information from Xamarin, but without success:</p>
  
  <p><a href="http://developer.xamarin.com/recipes/ios/network/web_requests/download_a_file/" rel="nofollow">http://developer.xamarin.com/recipes/ios/network/web_requests/download_a_file/</a>
  <a href="http://developer.xamarin.com/recipes/cross-platform/networking/download_progress/" rel="nofollow">http://developer.xamarin.com/recipes/cross-platform/networking/download_progress/</a></p>
  
  <p>This is my current code (with a working progress bar):</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  
  using Xamarin.Forms;
  using System.Net.Http;
  using System.IO;
  using System.Threading.Tasks;
  
  namespace DownloadExample
  {
      public partial class DownloadPage : ContentPage
      {
          public DownloadPage ()
          {
              InitializeComponent ();
  
              DownloadFile("https://upload.wikimedia.org/wikipedia/commons/3/3d/LARGE_elevation.jpg");
          }
  
          private async Task&lt;long&gt; DownloadFile(string url)
          {
              long receivedBytes = 0;
              long totalBytes = 0;
              HttpClient client = new HttpClient ();
  
              using (var stream = await client.GetStreamAsync(url)) {
                  byte[] buffer = new byte[4096];
                  totalBytes = stream.Length;
  
                  for (;;) {
                      int bytesRead = await stream.ReadAsync (buffer, 0, buffer.Length);
                      if (bytesRead == 0) {
                          await Task.Yield ();
                          break;
                      }
  
                      receivedBytes += bytesRead;
  
                      int received = unchecked((int)receivedBytes);
                      int total = unchecked((int)totalBytes);
  
                      double percentage = ((float) received) / total;
  
                      progressBar1.Progress = percentage;
                  }
              }
  
              return receivedBytes;
          }
      }
  }
  </code></pre>
  
  <p>Now, I need to save the file to my local storage. But, in this example, I'm not getting the file content, so I can't write it to my local storage. What do I need to change in the code to make this possible?</p>
  
  <p>FYI: In this example, I'm downloading an image, but it will be a .pdf / .doc / .docx in feature.</p>
  
  <p>Thanks in advance.</p>
  
  <p>BR, FG</p>