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