Tuesday, 18 June 2013

Upload Images in windows application inc#

How to upload Images in windows application in C# { OpenFileDialog _OPF = new OpenFileDialog(); _OPF.Filter = "Image Files|*.jpg;*.gif;*.bmp;*.png;*.jpeg|All Files|*.*"; //"JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif"; if (_OPF.ShowDialog() == DialogResult.OK) { Bitmap _img = new Bitmap(_OPF.FileName); Size size = new Size(200, 150); Bitmap bitmap = new Bitmap(_img, size); folderPath = Application.CommonAppDataPath + "\\images\\" + _OPF.SafeFileName; txtPhoto.Text = folderPath; _LatestImage = folderPath.ToString(); } }

Monday, 10 June 2013

How to send email from asp.net

How to send a mail private void button1_Click(object sender, EventArgs e) { if (_Emaild != null) { string _tomail = _Emaild; MailMessage mail = new MailMessage(); mail.To.Add(_tomail); mail.From = new MailAddress("suresh.jaglan2@gmail.com"); mail.Subject = txt_subject.Text; mail.Body = txt_contents.Text; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient("localhost", 25); smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address smtp.Credentials = new System.Net.NetworkCredential ("suresh.jaglan2@gmail.com", "Password"); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.EnableSsl = true; smtp.Send(mail); MessageBox.Show("Email Send Succfully"); } else { MessageBox.Show("Please enter Email-ID"); } }

Wednesday, 5 June 2013

How to create Cobmox with selected values in Gridview in C# Windows based.

public void setcombo() { DataTable dt = new DataTable(); DataColumn dc1 = new DataColumn("ID"); DataColumn dc2 = new DataColumn("Name"); dt.Columns.Add(dc1); dt.Columns.Add(dc2); dt.Rows.Add(1, "name1"); dt.Rows.Add(2, "name2"); DataGridViewComboBoxColumn c1 = new DataGridViewComboBoxColumn(); c1.DataSource = dt; c1.DisplayMember = "Name"; c1.ValueMember = "ID"; for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i]["ID"].ToString() == "2")//set the default value based on value member ID { c1.DefaultCellStyle.NullValue = dt.Rows[i]["Name"]; } } dataGridView1.Columns.Add(c1); }

How to get celltext values on text changed in Gridview asp.net C# Windows based.

Page load { dataGridView1.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dataGridView1_EditingControlShowing); } -------------------- private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { TextBox tx = e.Control as TextBox; DataGridViewTextBoxCell cell = (DataGridViewTextBoxCell)dataGridView1.CurrentCell; if (tx != null && cell.OwningColumn == dataGridView1.Columns[0]) { tx.TextChanged += new EventHandler(tx_TextChanged); } } void tx_TextChanged(object sender, EventArgs e) { string rate; TextBox tb = (TextBox)sender; if (!string.IsNullOrEmpty(tb.Text)) rate = tb.Text; else rate = ""; // double qty = Convert.ToDouble(dataGridView1.CurrentRow.Cells[0].Value); // dataGridView1.CurrentRow.Cells[2].Value = qty * rate; } }

Tuesday, 28 May 2013

How to bind Tree view from database in asp.net C#

http://www.codeproject.com/Articles/24534/How-to-load-data-from-database-to-TreeView

Thursday, 11 April 2013

How to Export Gridview to Excel in asp.net c#

public void button2_Click(object sender, EventArgs e) { Microsoft.Office.Interop.Excel._Application app = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing); Microsoft.Office.Interop.Excel._Worksheet worksheet = null; app.Visible = true; worksheet = workbook.Sheets["Sheet1"]; worksheet = workbook.ActiveSheet; worksheet.Name = "Exported from gridview"; for (int i = 1; i < dataGridView1.Columns.Count + 1; i++) { worksheet.Cells[1, i] = dataGridView1.Columns[i - 1].HeaderText; } for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { for (int j = 0; j < dataGridView1.Columns.Count; j++) { worksheet.Cells[i + 2, j + 1] = dataGridView1.Rows[i].Cells[j].Value.ToString(); } } //workbook.SaveAs("E:\\output.xls",Type.Missing, Type.Missing, Type.Missing, Type.Missing, //Type.Missing,Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive , Type.Missing, Type.Missing, Type.Missing, Type.Missing); //app.Quit(); }

Wednesday, 10 April 2013

Get latitude and Longitude

How to get Latitide and Longitude of an Address on text cahnage on button