Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello - Thanks in advance for your help. Working on re-learning MS VS2012.
OS Win 8.1.1, VS2012 Premium. .Net Framework v 4.5.51641. Visual C#

Trying to use -> IsOffLine to see if computer is connected to network.


From what I read online, ConnectivityStatus is in System.Web.ClientServices.

URL: http://social.msdn.microsoft.com/Search/en-US?query=connectivitystatus&emptyWatermark=true&ac=2[^]


However, I am getting the following error.
Error 1 The name 'ConnectivityStatus' does not exist in the current context c:\users\bob\documents\visual studio 2012\Projects\IsOffLine\IsOffLine\Program.cs 15 17 IsOffLine



Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.ClientServices;

namespace IsOffLine
{
class Program
{
static void Main(string[] args)
{
if (ConnectivityStatus.IsOffline)
{
Console.WriteLine("ConnectivityStatus is Off Line.");
Console.ReadLine();
}
else
{
Console.WriteLine("ConnectivityStatus is On Line.");
Console.ReadLine();
}
}
}
}
Posted

make sure that your project target framework > .net 4.0 and also add reference to Assembly: System.Web.Extensions (in System.Web.Extensions.dll)
 
Share this answer
 
thanks for the info. Questions- where do I set the project target framework ? and how do I add reference to Assembly? do I need to add System.Web.Extensions.dll ?

I added the line
using System.Web.Extensions, however the word Extensions is underlined in blue.

I now have -
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Extensions;

Is the above correct ? Thanks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900