How to check internet connection in Desktop Application ? [Resolved]

Posted by Akiii under C# on 5/18/2012 | Points: 10 | Views : 5848 | Status : [Member] | Replies : 5
Hi,

I am building a desktop application in which as soon as the application opens it must check for the internet connection. If available then it will open a page otherwise it will popup a messagebox stating check your internet connection.


Can anyone help in this regard ?


Thanks and Regards
Akiii




Responses

Posted by: Poonamkalra on: 5/18/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
Please refer the below URL:
http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.devices.network.isavailable.aspx

Below is the implemented sample:

Imports Microsoft.VisualBasic.Devices
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If My.Computer.Network.IsAvailable = True Then
MsgBox("Computer is connected.")
Else
MsgBox("Computer is not connected.")
End If
End Sub
End Class


Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Meet1424 on: 5/18/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
hi,
use following namespaces
----------------------------------
using System.Runtime;
using System.Runtime.InteropServices;
-----------------------------------
create a class
class CheckInternet
{
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
//Creating a function that uses the API function...
public static bool IsConnectedToInternet()
{
int Desc;
return InternetGetConnectedState(out Desc, 0);
}
}

in code behind of ur page on load or on any event on which u want to check..

bool CheckConnection=CheckInternet.IsConnectedToInternet()
if(CheckConnection==true)
{
//run your code
}
else

{
MessageBox.Show("No internet connection");
}

It is running n i used it yesterday in my windows application..


Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 5/18/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi poonam, thanks for the reply..

Do you have any other way to do this ?


Regards
Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 5/28/2012 [Member] Bronze | Points: 25

Up
0
Down
@Meet1424.......thanks !



Regards
Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Meet1424 on: 6/9/2012 [Member] Starter | Points: 25

Up
0
Down
@Akiii you are welcome but please mark my reply as answer dear.

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response