Solved

Detect open internet connection with C#

Posted on 2007-03-28
1
1,881 Views
Last Modified: 2013-12-17
I am developing a portable c# windows application using a MSDE and need to syncro to the main database when the laptop is connected to an internet connection.  I dont want the Syncro button to be enabled unless i can detect an open connection.  How do i detect that there is an open internet connection using c#
0
Comment
Question by:cdempster
1 Comment
 
LVL 15

Accepted Solution

by:
angus_young_acdc earned 500 total points
ID: 18822204
This code will check if you have an open connection :)

 HttpWebRequest req;
            HttpWebResponse resp;
            try
            {
                req = (HttpWebRequest)WebRequest.Create("http://www.google.com");
                resp = (HttpWebResponse)req.GetResponse();

                if (resp.StatusCode.ToString().Equals("OK"))
                {
                    MessageBox.Show("its connected.");
                }
                else
                {
                    MessageBox.Show("its not connected.");
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("Exception");
            }
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question