Check internet connection (availability) in Windows 8
13,769
Solution 1
I use this snippet without problems:
public static bool IsInternet()
{
ConnectionProfile connections = NetworkInformation.GetInternetConnectionProfile();
bool internet = connections != null && connections.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess;
return internet;
}
Solution 2
I had to use GetConnectionProfiles() and GetInternetConnectionProfile() to make it work across all devices.
class ConnectivityUtil
{
internal static bool HasInternetConnection()
{
var connections = NetworkInformation.GetConnectionProfiles().ToList();
connections.Add(NetworkInformation.GetInternetConnectionProfile());
foreach (var connection in connections)
{
if (connection == null)
continue;
if (connection.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess)
return true;
}
return false;
}
}
Related videos on Youtube
Author by
mert
Updated on September 15, 2022Comments
-
mert almost 2 years
How to check internet connection availability in Windows 8,C# development ? I looked at MSDN but page has been deleted.
-
Angshuman Agarwal over 11 yearsDuplicate of: stackoverflow.com/a/11797256/763026. Should be Closed.
-
-
yayadavid over 10 yearsHi Martin, how can I achieve the same thing in windows phone 8? I get get "Method or operation not implemented" exception in windows phone 8 using your snippet. Thanks in advance
-
sibbl over 8 yearsThis does not work if there are multiple connections, which e.g. may be the case in the emulators. Use the code from Joshua Heller below, which fixes the problem.
-
sibbl over 8 yearsThis also works if there are multiple internet connections - which may be the case in the Win 10 emulator and other circumstances.
-
Emy Blacksmith about 5 yearsWorks with Windows 10 SDK 1803 Build 17134