Skip to content

Instantly share code, notes, and snippets.

@dannycabrera
Created August 21, 2019 20:08
Show Gist options
  • Save dannycabrera/8d83a16235e5e76fca1064cc60b0b20e to your computer and use it in GitHub Desktop.
Save dannycabrera/8d83a16235e5e76fca1064cc60b0b20e to your computer and use it in GitHub Desktop.
FaxApp Util.cs
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
namespace FaxApp
{
public class Util
{
public async Task<string> DownloadFile(string url)
{
using (var client = new HttpClient())
{
using (HttpResponseMessage response = await client.GetAsync(url))
{
if (response.IsSuccessStatusCode)
{
var contentStream = await response.Content.ReadAsStreamAsync();
var filePath = Path.Combine(@"C:\Temp\FaxApp\Inbound\", $"{DateTime.Now.ToString("yyyyMMddHHmmss")}.pdf");
using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
{
await contentStream.CopyToAsync(fs);
}
return filePath;
}
}
}
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment