How to find if Network is Available in WP7 using C#?

How do one check if there is a open network connection in the Windows Phone 7 using c#? . You can achieve it through the static method GetIsNetworkAvailable() that is part of the NetworkInterface class .

You might require to include the namespace NetworkInformation incase you want to use this method.

using System.Net.NetworkInformation;

bool isAvailable = NetworkInterface.GetIsNetworkAvailable();

MessageBox.Show(isAvailable.ToString());

Note that when you use this method in the emulator , it will return always true , but in the device it should return the actual value .

The developers can also use the NetworkInterfaceType defined in the class “Microsoft.Phone.Net.NetworkInformation.NetworkInterface” property to detect the type of network connection .

MessageBox.Show(Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType.ToString());

The list of the Network Connection types are defined in the namespace “Microsoft.Phone.Net.NetworkInformation” and the
Microsoft.Phone.dll file .

Note that this will display Wireless80211 when i tried it in the emulator .

How do one check if there is a open network connection in the Windows Phone 7 using c#? . You can achieve it through the static method GetIsNetworkAvailable() that is part of the NetworkInterface class .

To know about the different connection types , you can find it on NetworkInterfaceType Enumeration

    6 Comments

  1. John
    April 21, 2011
    Reply

    Good stuff, thanks for the post.

  2. April 21, 2011
    Reply

    Thanks John

  3. Yogesh1985
    August 23, 2011
    Reply

    Microsoft.Phone.Net.NetworkInformation.NetworkInterface.NetworkInterfaceType.ToString()

    will return “None” if you r not connect to network.
    and will give you value “Wireless80211” if you r connecty to network irrespective of any network you are connected

  4. medouederni
    December 23, 2011
    Reply

    Thanks for the good post,
    I want to disable the wifi network connection in C#.
    How can I do that ??

  5. Saad Umair
    January 30, 2012
    Reply

    Hi,
    Following is my code:
    if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
    {
    MessageBox.Show(“Network Unavailable! This application cannot continue without network availability.”);
    }

    But i’m having the following run-time exception (it compiles fine):

    The type ‘System.Net.NetworkInformation.NetworkInterface’ exists in both ‘System.dll’ and ‘System.Net.dll’

    Please help me in this regard ASAP. Thanks a lot in advance.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this post, you will learn about sync provider notifications in Windows 11 and how to disable or enable it...
In this tutorial, let’s learn how to enable or disable the startup sound in Windows 11. By default, when Windows...
The CameraCaptureTask allows the Windows Phone 7 App to launch the Camera Application . This will be useful when the...