I am trying to read data from excel sheet from a URL (ex:- https://example.com). This URL will download an excel sheet to local machine but my requirement is to read data without downloading the file to local machine. I tried using StreamReader
but getting
System.Net.WebException
(the connection was aborted) error atreader.ReadToEnd()
.
Here is my code:
public static void GetStream()
{
String strURL = String.Empty;
strURL = "https://example.com";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL);
StreamReader reader;
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
reader = new StreamReader(response.GetResponseStream());
}
var en = reader.CurrentEncoding; //System.Text.UTF8Encoding
string val = reader.ReadToEnd();
}