Created
August 21, 2019 20:08
-
-
Save dannycabrera/8d83a16235e5e76fca1064cc60b0b20e to your computer and use it in GitHub Desktop.
FaxApp Util.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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