In console application i need to capture the output. There are 2 scenarios:
- Internet cannot display webpage
- Internet is working.
I am using below code
using(WebClient client = new WebClient())
{
string pageData;
try
{
pageData = client.DownloadString("https://google.com");
}
catch (HttpListenerException e)
{
Console.WriteLine("Exception is" + e);
}
Here I need to apply a condition that if Internet Explorer is displaying “Internet explorer cannot display the webpage” then it should show no connection. I need to capture the output.
You need to catch the WebException which is thrown when the web client cannot dowload the page for any reason. Try this:
See the WebClient documentation on MSDN for more detail.