title: how to download a file from URL in xamarin cross platform project using PCL Support
body: <p>I am new to Xamarin. Facing a lot of difficulties due to only a fraction of .Net assemblies are available for PCL.</p>
  
  <p>I need to download a .db file by hitting a URL which is required to save in local drive. As the project is in PCL So this is not allowing me to use System.IO.File in my project, so making me unable to do the file operations available in .Net class library.</p>
  
  <p>Ex: Suppose I am hitting the URL "<a href="http://123.com/register.db" rel="nofollow">http://123.com/register.db</a>" and this returns register.db as response. I need to save the register.db as it is in my local storage.</p>
  
  <p>My code to hit the URL is as below</p>
  
  <pre><code>public static async Task LaunchURLForSync(string targetUrl)
  {
      try
      {
          using (HttpClient client = new HttpClient())
          {
              using (HttpResponseMessage response = await client.GetAsync(targetUrl, HttpCompletionOption.ResponseHeadersRead))
              using (Stream streamToReadFrom = await response.Content.ReadAsStreamAsync())
              {
                  string fileToWriteTo = Path.GetFileName();
                  using (Stream streamToWriteTo = File.Open(fileToWriteTo, FileMode.Create)) // This doesn't work with PCL for ex. FIle.Open etc
                  {
                      await streamToReadFrom.CopyToAsync(streamToWriteTo);
                  }
              }
          }  
      }
      catch (Exception ex)
      {
          throw ex;
      }
  }
  </code></pre>
  
  <p>Any help will be highly appreciated. Thank you in advance :)</p>