pppppppppp

check internet Connection c#

check internet connection availiblty in c# .net

Method 1.

bool ConnectionExists()
{

try

{

System.Net.
IPHostEntry objIPHE = System.Net.Dns.GetHostEntry("www.google.com");

return true;
}

catch

{

return false;

}

}

Method 2.

bool ConnectionExists()
{

try

{

System.Net.Sockets.
TcpClient clnt = new System.Net.Sockets.TcpClient("www.google.com", 80);

clnt.Close();

return true;

}

catch (System.Exception ex)

{

return false;

}

}

Blog by: VidyaGyan

live cricket score on your website

live cricket score on your website

place this html code on your page to see live cricket score

<object align="middle" width="300px" height="273px" id="InsertWidget_82704aaf-e824-40ea-9d26-8fa17d878113" type="application/x-shockwave-flash" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"><param value="http://www.widgetserver.com/syndication/flash/wrapper/InsertWidget.swf" name="movie"><param value="high" name="quality"><param value="transparent" name="wmode"><param value="false" name="menu"><param value="r=2&amp;appId=82704aaf-e824-40ea-9d26-8fa17d878113" name="flashvars"><param value="sameDomain" name="allowScriptAccess"> <embed align="middle" width="300px" height="273px" flashvars="r=2&amp;appId=82704aaf-e824-40ea-9d26-8fa17d878113" allowscriptaccess="sameDomain" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" menu="false" quality="high" name="InsertWidget_82704aaf-e824-40ea-9d26-8fa17d878113" src="http://www.widgetserver.com/syndication/flash/wrapper/InsertWidget.swf">



</
object>






kill process web browser

kill process of  web browsers c#

using System.Diagnostics;

Process[] process_list = Process.GetProcesses();

foreach (Process process in process_list)

{

if (process.ProcessName.ToLower().Contains("firefox".ToLower()))

{

process.Kill();

}

else if (process.ProcessName.ToLower().Contains("chrome".ToLower()))

{

process.Kill();

}

else if (process.ProcessName.ToLower().Contains("iexplore".ToLower()))

{

process.Kill();

}

}

Auto Click

 

VidyaGyan


Auto Click Mouse C# Code

Auto Click, Auto Move,  Auto DoubleClick, Auto Right Click Mouse in C# .Net

//Create Class MouseWork
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Runtime.InteropServices;
using System.Collections;

class MouseWork
{
[
DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
[DllImport("user32")]
public static extern int SetCursorPos(int x, int y);
public void Click()
{
mouse_event(0x0002, 0, 0, 0, 0);
/* left button down value=0x0002 */
mouse_event(0x0004, 0, 0, 0, 0);/* left button down value=0x0004 */

}
public void Double_Click()
{
mouse_event(0x0002, 0, 0, 0, 0);
/* left button down value=0x0002 */
mouse_event(0x0004, 0, 0, 0, 0);/* left button down value=0x0004 */
Thread.Sleep(100);
mouse_event(0x0002, 0, 0, 0, 0);/* left button down value=0x0002 */
mouse_event(0x0004, 0, 0, 0, 0);/* left button down value=0x0004 */
}public void Right_Click()
{
mouse_event(0x0008, 0, 0, 0, 0);
/* right button down value=0x0008 */
mouse_event(0x0010, 0, 0, 0, 0); /* right button up value=0x0010 */
}public void Move_Cursor(int x, int y)
{
SetCursorPos(x, y);
//move_Cursor
}

}
//Note:Add your NameSpace if needed


//Using MouseWork Class
MouseWork mouse = new MouseWork();






mouse.Move_Cursor(0,0);

mouse.Click();

------------------------------------------------------------------------------------------------------

By: Pankaj Sharma

console shape


console shape Code


using
System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication8

{

class Program

{

static void Main()

{

Console.WriteLine("Shape 1:");







for (int i = 0; i < 7; i++)

{

for (int j = 0; j < 4; j++)

{

if ((((i + j) > 2) && (i <= 3)) || ((i > 3) && (j >= i - 3)))

{

Console.Write("*");

}

else

{

Console.Write(" ");

}

}
Console.WriteLine();

} Console.WriteLine("\nShape 2:");

for (int i = 0; i < 7; i++)

{

for (int j = 0; j < 7; j++)

{

if (((((i + j) > 2) && (j < 4)) || ((j - i <= 3) && (j >= 4))) && (i <= 3))

{

Console.Write("*");

}

else if ((i > 3) && (((j >= i - 3) && (j <= 3)) || ((j > 3) && (i + j < 10))))

{

Console.Write("*");

}

else

{

Console.Write(" ");

}

}
Console.WriteLine();

} Console.ReadLine();

}

}

}

screenshot


-----------------------------------------------------------------------------------------------------------

by: Pankaj Sharna

file download

File Download in C# Code


System.Net.WebClient downloader = new System.Net.WebClient();

downloader.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.Revalidate);

downloader.DownloadFileAsync(new Uri("http://www.domainName.com/apple.zip"), "d:\\newApple.zip");
---------------------------------------------------------------------------------------------------------------------------------------

by: VidyaGyan

send email

send email via C# .Net


System.Net.Mail.
MailMessage email = new System.Net.Mail.MailMessage();

email.To.Add("xyz@gmail.com"); //reciever email

email.From = new System.Net.Mail.MailAddress("myEmail@gmail.com", "your Name"); //sender email & display Name

email.Subject = "My First C# mail"; //message subject

email.Body = "i am testing my first e-mail program."; //message body

System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com"); //email server name

smtp.EnableSsl = true; //set false if your email server not using Ssl.

smtp.Credentials = new System.Net.NetworkCredential("myEmail@gmail.com", "password");//sender email & Password

smtp.Send(email);

by: Pankaj Sharma