Monday, May 28, 2012

Insert, Delete and Update in generic list in C#

Introduction
This Code for Insert Update and Delete in Generic List in ASP.Net with C#

Using This Code
Insert Update and Delete in List

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace GenericList
{
    public partial class frmContact : Form
    {
        List contacts;
        public frmContact()
        {
            InitializeComponent();
        }

        # region Insert Operation

        private void btnInsert_Click(object sender, EventArgs e)
        {
            Customer cnt = new Customer();
            cnt.Name = txtName.Text.Trim();
            cnt.Mobile = txtMobile.Text.Trim();
            contacts.Add(cnt);
            CurrencyManager cm = (CurrencyManager)this.BindingContext[contacts];
            cm.Refresh();
            dgcontacts.DataSource = contacts;
        }
        # endregion

        #region Update Operation

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            List select = contacts.FindAll(new Predicate(HasName));
            if (select.Count > 0) // record found
            {
                foreach (Customer cnt in select)
                {
                    cnt.Name = txtName.Text.Trim();
                    cnt.Mobile = txtMobile.Text.Trim();
                }
                CurrencyManager cm = (CurrencyManager)this.BindingContext[contacts];
                cm.Refresh();
                dgcontacts.DataSource = contacts;
            }
            else
            {
                MessageBox.Show("No records found");
            }
        }
        # endregion
        //This function will check for the person name
        bool HasName(Customer c)
        {
            return (c.Name == txtName.Text);
        }

        # region Delete Operation

        private void btnDelete_Click(object sender, EventArgs e)
        {
            List select = contacts.FindAll(new Predicate(HasName));
            if (select.Count > 0) // record found
            {
                foreach (Customer cnt in select)
                {
                    contacts.Remove(cnt);
                }
                CurrencyManager cm = (CurrencyManager)this.BindingContext[contacts];
                cm.Refresh();
                dgcontacts.DataSource = contacts;
            }
            else
            {
                MessageBox.Show("No records found");
            }
        }
        # endregion
        private void frmContact_Load(object sender, EventArgs e)
        {
            contacts = new List();
        }
    }

    //Customer Class

    public class Customer

    {

        private string _Name;

        private string _Mobile;

        public string Name

        {

            get { return _Name; }

            set { _Name = value; }

        }

        public string Mobile

        {

            get { return _Mobile; }

            set { _Mobile = value; }

        }

    }

}

Read more »

C# Code To make thumbnails of full size images

Intriduction

  This Code use for to mkae thumbnailspf full size images..  


This is to written in fileupload code behind

if (FileUpload4.FileName != "")
{
string appPath = Request.PhysicalApplicationPath;
path = appPath + "Images\\" + FileUpload4.FileName;
path6 = "Images/Thumbnail/" + FileUpload4.FileName;
FileUpload4.SaveAs(Server.MapPath("../Images/" + FileUpload4.FileName));

System.Drawing.Image ImageToSave = resizeImage(System.Drawing.Image.FromStream(FileUpload4.FileContent), new Size(150, 150));
// supply actual image to the function
ImageToSave.Save(Server.MapPath(System.IO.Path.Combine("../Images/Thumbnail/", FileUpload4.FileName)));
// the function returns a thumbnail which is saved here

}


This is drawing function that is place below above code

private static System.Drawing.Image resizeImage(System.Drawing.Image imgToResize, Size size)
{
int sourceWidth = imgToResize.Width;
int sourceHeight = imgToResize.Height;
float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ((float)size.Width / (float)sourceWidth);
nPercentH = ((float)size.Height / (float)sourceHeight);
if (nPercentH < nPercentW)
nPercent = nPercentH;
else
nPercent = nPercentW;
int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);
Bitmap b = new Bitmap(destWidth, destHeight);
Graphics g = Graphics.FromImage((System.Drawing.Image)b);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
g.Dispose();
return (System.Drawing.Image)b;
namespace to be included
using System.IO;
using
System.Drawing;
using
System.Drawing.Imaging;
using
System.Drawing.Drawing2D; 

Read more »

Online Payments Using Paypal with Asp.Net with C#

Introduction

this code for Online Payments Using Paypal with Asp.Net
Description

I am going to explain Step by Step Procedure, about integrating PayPal account with asp.

Step-1  Create a First Paypal Merchant Account.
            --this Account Create for Salling purpose.

Step-2  Create a Second Paypal Buyer Account.
             --this Account Create for purchasing purpose.

Using the code
I am going to explain Step by Step Procedure, about integrating PayPal account with asp.net Code.

you want to do online transaction using paypal. Use this Example in your project..

This Code is Declare on your Button Click Event.

const string Server_URL = "https://www.sandbox.paypal.com/cgi-bin/webscr?";
const string return_URL = "https://www.paypal.com/xclick/Sample@gmail.com";
const string cancelreturn_URL = "http://www.PageWhenCancel.com/cc.fail.aspx";

//Assigning Cmd Path as Statically to Parameter
string cmd = "_xclick";

//Assigning business Id as Statically to Parameter
string business = "tejasn_1338137871_biz@gmail.com";// Enter your business account here

//Assigning item name as Statically to Parameter
string item_name = "balagi waffers";

//Passing Amount as Statically to parameter
int amount = 1000;

//Passing Currency as Statically to parameter
string currency_code = "USD";

string redirect = "";

//Pass your Server_Url,cmd,business,item_name,amount,currency_code variable
redirect += Server_URL;
redirect += "cmd=" + cmd;
redirect += "&business=" + business;
redirect += "&item_name=" + item_name;
redirect += "&amount=" + amount;
redirect += "&currency_code=" + currency_code;
redirect += "&return=" + return_URL;
redirect += "&cancel_return" + cancelreturn_URL;
//Redirect to the payment page
Response.Redirect(redirect);


After Click on Send Button just follow this step
--when you purchase any one value using your seller id..
--Enter your id and password run time on paypal payment time..
Example of :- tejasbhalani_per@gmail.com 
This Code Sucessfully Run

Read more »

Sunday, May 27, 2012

Open PDF file in new browser tab using ASP.NET with C#

Introduction
This tip describes how to open a PDF file in a new browser tab using ASP.NET with C#.

Using the code
We create a folder in our project and store the PDF in this folder.

  //Java Script for that
<script type="text/javascript">
    function openPDF() {
        var strMessage = '<%= p%>';
        var a = 'http://localhost:2878/your project name/' + strMessage;
        window.open(a, 'PDF');
        return true;
    }
</script>

// Create one public variable p.
public string p;
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
p = e.CommandArgument.ToString();
this.Page.ClientScript.RegisterStartupScript(this.GetType(),
"page_index_script","openPDF();",true);
}
//p variable is provide path..
//For Example:-"E-book/tejasvbhalani.pdf"
//E-book is our folder name and tejasvbhalani is our pdf file name..

Read more »

Sending Email using C# and ASP.Net

Introduction
This tip describes how to send email using ASP.NET with C# and using a GMail or Yahoo! port.

Background

This code uses the System.Net.Mail namespace.

Using the code
//Sending Mail Using Gmail

const string FromAddress = "your gmail id";//For Example tejasbhalani@gmail.com
string Subject = TextBox6.Text;
String Body = TextBox4.Text;
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(ToAddress);
mail.From = new MailAddress(FromAddress)
mail.Subject = Subject;
mail.Body = Body;
mail.Priority = System.Net.Mail.MailPriority.High;
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential(FromAddress, "gmail id password");
client.Port = 587; // Gmail works on this port
client.Host = "smtp.gmail.com";
client.EnableSsl = true; //Gmail works on Server Secured Layer
try
{
client.Send(mail);
}
catch (Exception error)
{
throw error;
}

//Sending Mail Using Yahoo
//send mail using yahoo idstring ToAddress = txtto.Text;
const string FromAddress = "your Yahoo id";//For Example tejasvbhalani@yahoo.com
string Subject = txtsub.Text;
String Body = txtbody.Text;
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(ToAddress);
mail.From = new MailAddress(FromAddress);
mail.Subject = Subject;
mail.Body = Body; client.Credentials = new System.Net.NetworkCredential(FromAddress, "yahoo id password");
mail.Priority = System.Net.Mail.MailPriority.High;
SmtpClient client = new SmtpClient();
client.Port = 587;
client.Host = "smtp.mail.yahoo.com";
client.Send(mail);

Use Code For Send Mail to any emailid...........

Read more »

Followers