Is your client looking for a programming or design skill that you don't have? Refer a project to us, earn up to $10,000 in referral commission.
Geekpedia Tutorials Home

Building a C# Chat Client and Server

Building a C# Chat Client and ServerA step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.

in C# Programming Tutorials

Getting Hard Drive Information

Getting Hard Drive InformationA C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.

in C# Programming Tutorials

UPS Shipping Calculator

UPS Shipping CalculatorThis tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.

in PHP Programming Tutorials

Create Your Own Rich Text Editor

Create Your Own Rich Text EditorCreating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.

in JavaScript Programming Tutorials
Programming Tutorials
IT Jobs
From CareerBuilder

Check if HTTP connection to website is available

Sample code that uses a ConnectionAvailable() method to check whether the connection to an HTTP server went through or not. Can be used to check if a certain website is online as well as if Internet connection is available on the target machine.

On Sunday, September 23rd 2007 at 01:34 AM
By Andrew Pociu (View Profile)
*****   (Rated 4.3 with 14 votes)
Contextual Ads
More C# Resources
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Net;
  10. namespace Labs
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  19.         private void Form1_Load(object sender, EventArgs e)
  20.         {
  21.             // Returns True if connection to was successful
  22.             MessageBox.Show(ConnectionAvailable("").ToString());
  23.         }
  25.         public bool ConnectionAvailable(string strServer)
  26.         {
  27.             try
  28.             {
  29.                 HttpWebRequest reqFP = (HttpWebRequest)HttpWebRequest.Create(strServer);
  31.                 HttpWebResponse rspFP = (HttpWebResponse)reqFP.GetResponse();
  32.                 if (HttpStatusCode.OK == rspFP.StatusCode)
  33.                 {
  34.                     // HTTP = 200 - Internet connection available, server online
  35.                     rspFP.Close();
  36.                     return true;
  37.                 }
  38.                 else
  39.                 {
  40.                     // Other status - Server or connection not available
  41.                     rspFP.Close();
  42.                     return false;
  43.                 }
  44.             }
  45.             catch (WebException)
  46.             {
  47.                 // Exception - connection not available
  48.                 return false;
  49.             }
  50.         }
  51.     }
  52. }
Digg Digg It!     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this code snippet
Comment Current Comments
by senthilvel on Friday, November 30th 2007 at 01:30 AM

Ya this code was very nice. I am new to c#...I want to know how to check the Pre-defined text in that web site. can any one tell me?....

by senthilvel on Friday, November 30th 2007 at 01:47 AM

Hi Andrei..
I read your code in following link.

i am new to .Net. Can you tell me How to check the pre_defined text in that web page. For example, when i give as a url, there will be some predefined text like web,Image,News,Groups etc..

can you tell me how to find that type of text (eg:, web)....pls send soon...

thanks in advance..


by Huzefa on Friday, May 23rd 2008 at 07:03 AM

Hi Andrei,

this particular piece of code works if there is Internet connection available on the server where this files are hosted.

I am looking for a code that works at client side ie . it doesnt require a internet connection on that particular server.
Can you provide me with such code or give a hint as to where to look for it

by Cuong Nguyen on Thursday, October 23rd 2008 at 11:50 PM

Hi Andrew,
Nice code,

by Jai on Thursday, January 15th 2009 at 02:32 PM

Nice code... :)
But how to check whether https:// site is working or not?

It is always going to the Webexception.

by Ray on Tuesday, January 27th 2009 at 12:54 PM

Thank you, I have used this code and it works!

by manesti on Friday, July 23rd 2010 at 11:33 AM

Thanks it works like magic

by Vikram on Tuesday, July 27th 2010 at 10:19 AM

I'm trying a similar notion but on a lan and im not aware of the link till the last moment so can you give me some guidance how can i do it.

by Belson on Monday, September 27th 2010 at 04:22 AM

Nice code,

by Joel on Monday, November 8th 2010 at 09:00 PM

There are still a bunch of errors after adding all the referrences I can find that mach the using system.whatever. How do you remove all the errors so that you can run the code?

by Squidoo Lenses on Sunday, December 18th 2011 at 11:58 AM

Since this method only returns the age in years, it should return 0, and i think that's ok because the child is 1 day 0 years old? and thx for instructiv code

other question :
if a child is born this morning what is then most probable date of conception ? Nate,

Minor nitpick, but that could make the calculation incorrect for leap years.

by SnowDianna29 on Tuesday, December 27th 2011 at 05:01 PM

Make your life more easy take the business loans and all you require.

by Ahsan on Friday, November 23rd 2012 at 05:46 AM

I want to check SEOMoz Page Authority on same platform C#. Which code should i use to fetch the page authority of any site.

Comment Comment on this tutorial
Name: Email:
Comment Related Source Code
There is no related code.

Comment Related Tutorials
There are no related tutorials.

Jobs C# Job Search
My skills include:

Enter a City:

Select a State:

Advanced Search >>
Discover Geekpedia