Post: C# Check if website is online/offline?
05-27-2013, 11:29 AM #1
makeabce
I defeated!
(adsbygoogle = window.adsbygoogle || []).push({}); Probbably asked before,but anyway.
I was wondering how i could make C# program check if a website is online/offline,example if i type IP to a textbox,press a button and it checks the status,if it's offline/online then it would set label text to a offline or online.
:|
(adsbygoogle = window.adsbygoogle || []).push({});
05-27-2013, 12:18 PM #2
OmGRhys-x
Are you high?
Originally posted by makeabce View Post
Probbably asked before,but anyway.
I was wondering how i could make C# program check if a website is online/offline,example if i type IP to a textbox,press a button and it checks the status,if it's offline/online then it would set label text to a offline or online.
:|



you can try this mate

System.Net.NetworkInformation.Ping

    var ping = new System.Net.NetworkInformation.Ping();

var result = ping.Send("www.google.com");

if (result.Status != System.Net.NetworkInformation.IPStatus.Success)
return;

IF u want to type in the url then change the You must login or register to view this content. to (textBox1.Text);
Hope i helped Smile
05-27-2013, 04:23 PM #3
makeabce
I defeated!
Originally posted by x View Post
you can try this mate

System.Net.NetworkInformation.Ping

    var ping = new System.Net.NetworkInformation.Ping();

var result = ping.Send("www.google.com");

if (result.Status != System.Net.NetworkInformation.IPStatus.Success)
return;

IF u want to type in the url then change the You must login or register to view this content. to (textBox1.Text);
Hope i helped Smile


...where i can see the result? :| No where.
How i could make the result be shown in a textbox/label?

Originally Posted by makeabce
Probbably asked before,but anyway.
I was wondering how i could make C# program check if a website is online/offline,example if i type IP to a textbox,press a button and it checks the status,if it's offline/online then it would set label text to a offline or online.
05-27-2013, 04:54 PM #4
Sonoro
I like anteaters
This is exactly what you're searching for:

    public bool IsOnline(string website)
{
try
{
HttpWebRequest Request = (HttpWebRequest)HttpWebRequest.Create(website);

HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
if (HttpStatusCode.OK == Response.StatusCode)
{
// Website is Online
Response.Close();
return true;
}
else
{
// Website if Offline
Response.Close();
return false;
}
}
catch (WebException)
{
// Connection is not available
return false;
}


}



Here's an example of the use

    public void button1_Click(object sender, EventArgs e)
{
if (IsOnline(textBox1.Text) == true)
{
string Status = "Site is Up";
label1.Text = Status;
}
else
{
string Status = "Site is Down";
label1.Text = Status;
}

}




Hope it helps :p

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo