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

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

You May Also Like

This blog post will guide you through several effective methods to troubleshoot and resolve the issue of Microsoft Edge not...
Windows 11 offers a range of audio enhancements that can enrich your listening experience. These enhancements include features like virtual...
Windows 11 brings a fresh and visually stunning design to your desktop, and one of the standout features is the...