Results 1 to 1 of 1

Thread: Test For Internet Connection

  1. #1

    Thread Starter
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256

    Test For Internet Connection

    Someone once asked for help to test for an internet connection. Well here is the code to do it.
    Code:
    private bool IsConnectionAvailable(string url)
    {
    	bool isConnected = false;
    
    	HttpWebRequest req;
    	HttpWebResponse res;
    			
    	try
    	{
    		req = (HttpWebRequest)WebRequest.Create(url);
    		res = (HttpWebResponse)req.GetResponse();
    		req.Abort();
    				
    		if(res.StatusCode == HttpStatusCode.OK)
    			isConnected = true;
    		}
    		
                    catch(WebException webEx)
                    {
    			MessageBox.Show(webEx.Message);
    			isConnected = false;
    		}
    		catch(Exception ex)
    		{
    			MessageBox.Show(ex.Message);
    			isConnected = false;
    		}
    		return isConnected;
    	}
    }
    Last edited by DevGrp; Oct 24th, 2002 at 08:27 PM.
    Dont gain the world and lose your soul

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width