pppppppppp

run application in as administrator in c sharp

Run application in as administrator in c sharp

     start your application in administrator permissions using c sharp
 
using System.Diagnostics;
using System.Security.Permissions;
using System.Threading;
using System.Security.Principal;

namespace WindowsFormsApplication2
{
  public partial class Form1 : Form
   {
       public Form1()
        {
            InitializeComponent();
         }         

       private void Form1_Load(object sender, EventArgs e)
        {
           button1.Text =
"Run Firefox with administrator permission";
        }
      private void button1_Click(object sender, EventArgs e)
       {
          MyMethod();
        }

      public void MyMethod()
       {
          ProcessStartInfo info = new ProcessStartInfo(@"C:\Program Files\Mozilla Firefox 13\firefox.exe");
         if (System.Environment.OSVersion.Version.Major >= 6)
              {
                  info.Verb =
"runas";
              }             
           Process p = Process.Start(info);

        }
     }
}


Output  Image
 
By:VidyaGyan
 

MySql database Connection in C Sharp

 

MySql database connection in c sharp

this is mySql database connectivity using System.Data.Odbc; 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;

namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
try
{
string MyConString = "DRIVER={MySQL ODBC 3.51 Driver};" +"SERVER=www.BombayAccessories.com;" +"DATABASE=database1;" +"UID=Bombay;" +"PASSWORD=Accessories;" +"OPTION=3";
OdbcConnection MyConnection = new OdbcConnection(MyConString);
OdbcDataAdapter sda = new OdbcDataAdapter("select * from Products", MyConnection);
DataTable dt=new DataTable();
sda.Fill(dt);
dataGridView1.DataSource=dt;

}
catch (Exception ei)
{
MessageBox.Show(ei.Message);
}
}
}
}


OutPut Image:
 
 
By: VidyaGyan
 

CODING FOR WEB SERVICES FOR PAYMENT


CODING FOR WEB SERVICES FOR PAYMENT

using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
...
/// <summary>
/// Summary description for PaymentService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class PaymentService : System.Web.Services.WebService {
SqlConnection con;
public PaymentService () {

//Uncomment the following line if using designed components
//InitializeComponent();
}

[WebMethod]
public bool checkcard(int cno, int pno)
{
con=new SqlConnection(@"Data Source=.\SQLEXPRESS;User Instance=true;AttachDbFilename=C:\Users\radiant\Documents\Visual Studio 2010\WebSites\WebSite4\App_Data\DB.mdf;Integrated Security=SSPI");
con.Open();
string qry = "select * from cardpay where cardno=" + cno+"and pinno="+pno;
SqlDataAdapter da = new SqlDataAdapter(qry, con);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count == 0)
return false;
else
return true;

}

}

Remove desktop wallpaper in c sharp

C# Program to remove desktop wallpaper



using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Shell32; //"Microsoft Shell Control And Automation"
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
class Program
{
[
DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern Int32 SystemParametersInfo(UInt32 action, UInt32 uParam, String vParam, UInt32 winIni);
private static readonly UInt32 SPI_SETDESKWALLPAPER = 0x14;
private static readonly UInt32 SPIF_UPDATEINIFILE = 0x01;
private static readonly UInt32 SPIF_SENDWININICHANGE = 0x02;

static void Main(string[] args)
{
string path = "";

SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, path, SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);

}
}
}

hide windows taskbar in c#

Hide windows taskbar  C# Program

 public static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll")]

public static extern Int32 SendMessage(

int hWnd, // handle to destination window

int Msg, // message

int wParam, // first message parameter

int lParam); // second message parameter

private void Form1_Load(object sender, EventArgs e)

{

Process p = new Process();

p.StartInfo.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.System);

p.StartInfo.FileName = "taskmgr.exe";

p.StartInfo.CreateNoWindow = true;

p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

p.Start();

}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)

{

const int WM_CLOSE = 0x0010;

int taskManager = FindWindow("#32770", "Windows Task Manager");

SendMessage(taskManager, WM_CLOSE, 0, 0);

}

Zip file & Folder Asp.Net ,C#

 Zip in Asp.Net, C#

string sPath = Server.MapPath("~") + "DownloadFolder";

string sPath = Server.MapPath("~") + "DownloadFolder";

string zipFullPath = Server.MapPath("~") + "DocumentFolder.zip";

ZipOutputStream zipOut = new ZipOutputStream(File.Create(zipFullPath));

foreach (string fName in Directory.GetFiles(sPath))

{

FileInfo fi =
new FileInfo(fName);

ZipEntry entry = new ZipEntry(fi.Name);

FileStream sReader = File.OpenRead(fName);byte[] buff = new byte[Convert.ToInt32(sReader.Length)];

sReader.Read(buff, 0, (int)sReader.Length);

entry.DateTime = fi.LastWriteTime;

entry.Size = sReader.Length;

sReader.Close();

zipOut.PutNextEntry(entry);

zipOut.Write(buff, 0, buff.Length);

}

zipOut.Finish();

zipOut.Close();

Dont forget to import the fully qualified namespace using ICSharpCode.SharpZipLib.Zip ;)

By: VidyaGyan

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