I am looking for a way to download an excel file from a url using httpWebRequest and parse it somehow - whether this means converting it to a .csv file so I can simply use TextFieldParser
or leaving it as an excel file, I don't know.
private byte[] GetExcelFile()
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create("url_To_Excel_File");
httpWebRequest.ContentType = "application/vnd.ms-excel";
httpWebRequest.Method = "GET";
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
try
{
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var contents = streamReader.ReadToEnd();
return contents;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw;
}
}
It is my understanding that contents
should be an array of bytes? How can I correctly download this excel file and parse the response?