1

I have a Metro app done using C# & XAML. I'm using the WebView control to load a URL, and also using Notifications to update the tiles. If the machine isn't connected to the internet, the tile, and the webview are blank. I want to be display some sort of a message indicating that the app isn't able to connect to the Internet.

How do I check for Internet connection? In a try catch block or something?

1 Answer 1

2

Have you looked at the Network Information sample? It shows how to check for internet connectivity from inside your app. Short version...

var connectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();

switch (connectionProfile.GetNetworkConnectivityLevel())
                {
                    case NetworkConnectivityLevel.None:
                        connectionProfileInfo += "Connectivity Level : None\n";
                        break;
                    case NetworkConnectivityLevel.LocalAccess:
                        connectionProfileInfo += "Connectivity Level : Local Access\n";
                        break;
                    case NetworkConnectivityLevel.ConstrainedInternetAccess:
                        connectionProfileInfo += "Connectivity Level : Constrained Internet Access\n";
                        break;
                    case NetworkConnectivityLevel.InternetAccess:
                        connectionProfileInfo += "Connectivity Level : Internet Access\n";
                        break;
                }

Make a check before trying to use the WebView and prompt the user accordingly.

1
  • Awesome, thank you so much. I'll lookup the Network sample as well.
    – tempid
    Oct 15, 2012 at 20:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.