people in couch

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’ll learn about the Win32 Error “0x000019E5 – ERROR_COULD_NOT_RESIZE_LOG” that you get when debugging system erors in...
In this post, you’ll learn about the error “CO_E_DBERROR 0x8004E02B” that is returned when working with COM based APIs or...
In this post, you’ll learn about the Win32 Error “0x000019D0 – ERROR_LOG_BLOCK_VERSION” that you get when debugging system erors in...