I am facing problem for download ing pdf file from api via c# code.I have already asked this questions in stackoverflow and I have get the answer from stackoverflow with below source code. This source code works fine only in visual Studio 2012 and above version. But I am using visual Studio 2010 with .Net framework 4.0 version. The below code is not working in visual Studio 2010 due compatibility issue (asynch and await keyword not supported). My question is what is the alternate source code for working in visual Studio 2010.
static string url = "https://einvoicing.internal.cleartax.co/v2/eInvoice/download?irns=7b46fb61d6e0883bdfdfb997ca25c4b5629d3062241532f6e8e6fcdfc0a95c9a";
static HttpClient client = new HttpClient();
static async Task DownloadCurrentAsync(string StrInvoiceNo)
{
client.DefaultRequestHeaders.Add("owner_id", "78c6beda-54a2-11ea-b064-0af3f8b02c24");
client.DefaultRequestHeaders.Add("gstin", "29AAFCD5862R000");
HttpResponseMessage response = await client.GetAsync(url);
response.EnsureSuccessStatusCode(); // <= Will throw if unsuccessful
using (FileStream fileStream = new FileStream(StrInvoiceNo.Replace("/","-") + ".pdf", FileMode.Create, FileAccess.Write, FileShare.None))
{
//copy the content from response to filestream
await response.Content.CopyToAsync(fileStream);
System.Diagnostics.Process.Start(StrInvoiceNo.Replace("/", "-") + ".pdf");
}
}