Popular Posts

Tuesday, June 14, 2011

how to compare any date value with the current system date in c#

      *dtpDate.Value > DateTime.Now
OR *dtpDate.Value<DateTime.Now
OR *dtpDate.Value<=DateTime.Now
You may apply any operator in between the two values in order to compare.
Here the value marked star can be any value you wish to compare with the system date.

Tuesday, April 12, 2011

Make Life Easy: Behind the scenes of a ASP.NET code

Make Life Easy: Behind the scenes of a ASP.NET code: "What exactly happens when an ASP.NET receives a request for the Codename.aspx First the request for the page is sent to the web server.If y..."

Friday, March 11, 2011

Behind the scenes of a ASP.NET code

What exactly happens when an ASP.NET receives a request for the Codename.aspx

First the request for the page is sent to the web server.If you're running a live site ,the web server is almost certainly IIS.

IF YOUR RUNNING THE PAGE IN VISUAL STUDIO:
The request is sent to the built in Visual Studio's test server.

2.The web server determines the .aspx extension is registered with ASP.NET and passes it to the ASP.NET worker process.If the file extension belonged to another service(as it would for .asp or .html files),ASP.NET would never get evolved.

3.If this is the first time the page in this application has been requested,ASP.NET automatically creates the application domain .It also compiles all the web page code for optimum performance ,and caches the compiled files in the directory C:\Windows\Microsoft.NET\framework\v2.0.570727\Temporary ASP.NET files.If this task has already been performed ,ASP.NET will reuse the compiled version of the page.

4.The compiled Codename.aspx page acts like a miniature program.It starts firing events(most probably in the
Page.Load event).However,you haven't created an event handler for the event,so no code returns.At this stage,everything is working together as a set of in-memory .NET objects

5.When the code is finished,ASP.NET asks every control in the web page to render itself into the corresponding HTML markup.

6.The final page is sent to the user,and the application ends.

Monday, March 7, 2011

Code to send email through C# .net using Gmail server(complete detailed description)


PROCEDURE
           How to obtain details of the server u want to send an email through
on command prompt follow the following steps

1.c:\nslookup
2.>set type=mx
3.>enter the server name (example : google.com)
4.Press enter

COMPLETE PROCEDURE:

(Follow these steps step-wise in your command prompt)

c:\>nslookup
Default Server:  UnKnown
Address:  218.248.241.4
> set type=mx
> google.com
Server:  UnKnown
Address:  218.248.241.4

Non-authoritative answer:
google.com      MX preference = 300, mail exchanger = google.com.s9b1.psmtp.com
google.com      MX preference = 400, mail exchanger = google.com.s9b2.psmtp.com
google.com      MX preference = 100, mail exchanger = google.com.s9a1.psmtp.com
google.com      MX preference = 200, mail exchanger = google.com.s9a2.psmtp.com

google.com      nameserver = ns2.google.com
google.com      nameserver = ns3.google.com
google.com      nameserver = ns4.google.com
google.com      nameserver = ns1.google.com
google.com.s9a1.psmtp.com       internet address = 74.125.148.10
google.com.s9a2.psmtp.com       internet address = 74.125.148.11
google.com.s9b1.psmtp.com       internet address = 74.125.148.13
google.com.s9b2.psmtp.com       internet address = 74.125.148.14
ns1.google.com  internet address = 216.239.32.10
ns2.google.com  internet address = 216.239.34.10
ns3.google.com  internet address = 216.239.36.10
ns4.google.com  internet address = 216.239.38.10
>



UR C# .NET CODE:
DESIGN


FORM :










CODE:
(copy this code in the forms code)
(please verify the namespace)


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

namespace Mailing
{
    public partial class Mail : Form
    {
        public Mail()
        {
            InitializeComponent();
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage message = new MailMessage(txtFrom.Text, txtTo.Text, txtSubject.Text,    txtBody.Text);
                message.Priority = MailPriority.High;
                message.IsBodyHtml = true;
                SmtpClient emailclient = new SmtpClient();
emailclient.Credentials = new    System.Net.NetworkCredential("your email     address","youremailpassword");
                emailclient.Port = 587;                                   //port number for gmail
                emailclient.Host = "smtp.gmail.com";              //gmail host SMTP server
                emailclient.EnableSsl = true;                          //for security purpose
              
                try
                {
                    emailclient.Send(message);
                    MessageBox.Show("Message Sent");
                }
                catch (Exception ae)
                {
                    MessageBox.Show(ae.ToString());
                }


            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}

Monday, February 21, 2011

Good feature of C#:Partial classes

Partial classes give you the ability to split a class into more than one source code .cs file.
If a class becomes particularly long and intricate you might decide to break it into pieces as shown below


//This file is stored in the Product.cs

public partial class Product
{
private string name;
private decimal price1;
public string Name
{

}

public decimal Price
{

}

public string ImageUrl
{

}

}

public partial class Product
{
//continued code here
}



these two  partial classes comprise one class Product and are divided to simplify coding.