Friday, February 17, 2012

Drag & Drop: Drag and Drop - Resizable Panel

This example demonstrates one way to implement a resizable panel using the Drag & Drop Utility. (Note: The Container Family of UI controls contains a Panel Resize Example that also provides useful code for building resizable panels.)








please visit for live demo an download:
http://developer.yahoo.com/yui/examples/dragdrop/dd-resize.html

Tuesday, February 14, 2012

Fetch and Read emails from POP3 mail server using C# and VB.Net

In this article I will explain how to read emails from pop3 server using the free open source library OpenPop.Net. This library provides you very easy API to access and read emails from the POP3 Servers.
Though the attached sample code has the OpenPop.DLL, still for reference you can download this library from the following URL
Once you have the library we can start building our sample application that will access and read emails from the POP3 servers. You will need to add the reference of the OpenPop.DLL to your project using Add Reference option in Visual Studio
HTML Markup
<form id="form1" runat="server">
Mail Server Name:
<asp:TextBox ID="txtMailServer" runat="server" />
<br />
UserName:
<asp:TextBox ID="txtUserName" runat="server" />
<br />
Password:
<asp:TextBox ID="txtPassword" runat="server" TextMode = "Password" />
<br />
Port:
<asp:TextBox ID="txtPort" runat="server" Text = "110" />
<br />
SSL:
<asp:CheckBox ID="chkSSL" runat="server" />
<br />
<asp:Button ID="btnReadEmails" runat="server" Text="Read Emails" OnClick = "Read_Emails" />
<br /><hr />
<asp:GridView ID="gvEmails" runat="server" AutoGenerateColumns = "false">
<Columns>
    <asp:BoundField HeaderText = "From" DataField = "From" />
    <asp:HyperLinkField HeaderText = "Subject" DataNavigateUrlFields = "MessageNumber" DataNavigateUrlFormatString = "~/ShowMessageCS.aspx?MessageNumber={0}" DataTextField = "Subject" />
    <asp:BoundField HeaderText = "Date" DataField = "DateSent" />
</Columns>
</asp:GridView>
</form>
Above you will notice that I have added the Textboxes for various parameters like Mail Server, Username, Password, Port Number of the mail server and a checkbox to allow users define whether the mail server requires SSL or not.
I have also placed an ASP.Net GridView control which will display the emails in tabular format to the users. I have added an asp:HyperLinkField for the Message Subject so that when it is clicked the complete message is displayed to the user.
Namespaces
C#
using OpenPop.Pop3;
using OpenPop.Mime;
using System.Data;

VB.Net
Imports OpenPop.Pop3
Imports OpenPop.Mime
Imports System.Data
Fetching and Reading list of emails from server
On the click of the button btnReadEmails we will execute the event Read_Emails which will fetch and read emails from the POP3 server.
C#
protected void Read_Emails(object sender, EventArgs e)
{
    Pop3Client pop3Client;
    if (Session["Pop3Client"] == null)
    {
        pop3Client = new Pop3Client();
        pop3Client.Connect(txtMailServer.Text, int.Parse(txtPort.Text), chkSSL.Checked);
        pop3Client.Authenticate(txtUserName.Text, txtPassword.Text);
        Session["Pop3Client"] = pop3Client;
    }
    else
    {
        pop3Client = (Pop3Client)Session["Pop3Client"];
    }
    int count = pop3Client.GetMessageCount();
    DataTable dtMessages = new DataTable();
    dtMessages.Columns.Add("MessageNumber");
    dtMessages.Columns.Add("From");
    dtMessages.Columns.Add("Subject");
    dtMessages.Columns.Add("DateSent");
    int counter = 0;
    for (int i = count; i >=1 ; i--)
    {
        Message message = pop3Client.GetMessage(i);
        dtMessages.Rows.Add();
        dtMessages.Rows[dtMessages.Rows.Count - 1]["MessageNumber"] = i;
        dtMessages.Rows[dtMessages.Rows.Count - 1]["Subject"] = message.Headers.Subject;
        dtMessages.Rows[dtMessages.Rows.Count - 1]["DateSent"] = message.Headers.DateSent;
        counter++;
        if (counter > 5)
        {
            break;
        }
    }
    gvEmails.DataSource = dtMessages;
    gvEmails.DataBind();
}

VB.Net
Protected Sub Read_Emails(ByVal sender As Object, ByVal e As EventArgs)
        Dim pop3Client As Pop3Client
        If (Session("Pop3Client") Is Nothing) Then
            pop3Client = New Pop3Client
            pop3Client.Connect(txtMailServer.Text, Integer.Parse(txtPort.Text), chkSSL.Checked)
            pop3Client.Authenticate(txtUserName.Text, txtPassword.Text)
            Session("Pop3Client") = pop3Client
        Else
            pop3Client = CType(Session("Pop3Client"), Pop3Client)
        End If
        Dim count As Integer = pop3Client.GetMessageCount
        Dim dtMessages As DataTable = New DataTable
        dtMessages.Columns.Add("MessageNumber")
        dtMessages.Columns.Add("From")
        dtMessages.Columns.Add("Subject")
        dtMessages.Columns.Add("DateSent")
        Dim counter As Integer = 0
        Dim i As Integer = count
        Do While (i >= 1)
            Dim message As Message = pop3Client.GetMessage(i)
            dtMessages.Rows.Add()
            dtMessages.Rows((dtMessages.Rows.Count - 1))("MessageNumber") = i
            dtMessages.Rows((dtMessages.Rows.Count - 1))("From") = message.Headers.From.Address
            dtMessages.Rows((dtMessages.Rows.Count - 1))("Subject") = message.Headers.Subject
            dtMessages.Rows((dtMessages.Rows.Count - 1))("DateSent") = message.Headers.DateSent
            counter = counter + 1
            i = i - 1
            If counter = 5 Then
                Exit Do
            End If
        Loop
        gvEmails.DataSource = dtMessages
        gvEmails.DataBind()
End Sub
In the above code snippet I am using the Pop3Client class OpenPop.Net Library to connect to the POP3 server and fetching the emails. Below are the steps that describes how the library works
1. The client connects to the POP3 server using the server URL and Port Number
2. The client authenticates the user based on username and password.
3. The client fetches the total count of the messages on the server.
4. Based on the count we run a loop and start fetching the emails from the server.
Note: Since fetching emails is a time consuming process I am fetching only latest 5 emails from the server. You can later on remove that condition as per your requirement
With this we come to the end of this article. This article also has a second part where I will explain how to read and fetch the body of email. The complete code will be available in the Part II of this article series.

Fetch and Read emails from POP3 mail server using C# and VB.Net – Part II  >>


for futher detail: and download this all code please visit:
http://aspsnippets.com/Articles/Fetch-and-Read-emails-from-POP3-mail-server-using-C-and-VB.Net---Part-I.aspx

Building the Chat Client and Server chat

In this two part tutorial you will learn how to create a chat client that connects to a chat server and exchanges messages with all the other connected clients. The first part covers the development of the client application.

Please visit :
http://www.geekpedia.com/tutorial239_Csharp-Chat-Part-1---Building-the-Chat-Client.html
Regards:
Tahir from Pakistan

School Management System complete project download

School Management System complete project download and enjoy:
Please visit this site:
http://www.dotnetspider.com/projects/6-School-Management-System.aspx

Friday, February 10, 2012

Get date and time of server

 DateTime time = DateTime.Now;              
 
string format = "MMM ddd d HH:mm yyyy";

 
var dt = time.ToString(format);
Here we display time and date using label or Textbox. 

style sheet

body, ul, li
{       
    vertical-align:top;    
    font-weight:bold;
    font-family:Corbel;
    text-align:left;
    padding:0px 0px 0px 0px;
    margin:0px 0px 0px 0px;
}
#menu {
    list-style:none;

    height:40px;
    padding:0px 0px 0px 0px;
    /* Rounded Corners */
    /* Background color and gradients */
   
    background: #3a3a3a;
    /*background: -moz-linear-gradient(top, #9c9c9c, #9c9c9c);*/
    /*background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#9c9c9c), to(#9c9c9c));*/
}
#menu li {
    float:left;
    display:block;
    text-align:left;
    position:relative;
    padding: 10px 0px 13px 0px;
    margin-right:0px;
    margin-top:0px;
    border:none;
}

#menu li:hover {
    /*border: 1px solid #ee2449;*/
   /* padding: 10px 2px 10px 2px;*/
    /* Background color and gradients */
    background: #0084c5;
    /*background: -moz-linear-gradient(top, #ee2449, #ee2449);*/
    /*background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#F4F4F4), to(#ee2449));*/
    /* Rounded corners */
}

#menu li a {
    font-family:Corbel;
    font-size:14px;
    color:#0084c5;
    display:block;
    outline:0;
    text-decoration:none;
   
}
#menu li .drop
{
    padding-left:15px;
    padding-right:12px;
    color:White;
    text-align:center;
    background:url("img/drop.png") no-repeat;
}
html,body
{
   
        height:100%;
}
.TopBanner
{
    background-color:White;
    height:70px;
    font-family:Corbel;
    font-size:12pt;
    color:White;
}

.MenuBar
{
    padding:0px 0px 0px 0px;
    margin:0px 0px 0px 0px;
    max-height:40px;
    vertical-align:top;
}
.ContentArea
{
    background-color:White;   
    text-align:left;
    height:330px;
    vertical-align:top;
}

.Labelh1
{
    font-family:Corbel;
    font-size:12pt;
    font-weight:bold;
    color:Black;   
}
.Textbox
{
    font-family:Corbel;
    font-size:12pt;
    font-weight:normal;

    border: 1px solid #9c9c9c;
}
.button
{
    FONT-FAMILY: 'Corbel';
       FONT-SIZE: 9pt;
    height: 16pt;
    color: white;
    font-weight:lighter;
    background-color: #ee2449;
    border: 1px solid  #9c9c9c;   
    cursor : pointer;
    -moz-border-radius: 5px 5px 5px 5px;
    -webkit-border-radius: 5px 5px 5px 5px;
    -behavior: url(Include/ie-css3.htc);
   
}
#container {
        min-height:100%;
        position:relative;
    }
   
    #body {
       
        padding-bottom:30px;
       
    }
    #footer {
        position:absolute;
        bottom:0;
        width:100%;                           
        background-color:Green;
        color:White;
        height:20px;/* Height of the footer */
        font-family:Corbel;
        font-size:12pt;
        vertical-align:middle;       
        text-align:center;
    }
   
   


Drop down menu and header and stick footer

<body>
    <div id="container">
        <div id="body">
            <form id="form1" runat="server">
                <table id="MainTable" width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr align="center" style="height: 100%; width: 100%;">
                        <td style="width: 100%; background-color: Black;">
                            <table width="100%" cellpadding="0" cellspacing="0">
                                <tr id="trTopBanner" class="TopBanner">
                                    <td>
                                        <table cellpadding="0" cellspacing="0" width="100%" border="0">
                                            <tr>
                                                <td style="vertical-align: top;">
                                                    <table cellpadding="0" cellspacing="0" width="100%" border="2">
                                                        <tr style="height: 70px; background-color: White">
                                                            <td align="center">
                                                                <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/logo2.jpg" />
                                                            </td>
                                                            <td align="center" style="text-align: center">
                                                                <p style="color: Red; text-align: center; font-size: 17pt; font-weight: bold">
                                                                    Welcome to Lahore
                                                                </p>
                                                            </td>
                                                            <td style="background-color: Navy">
                                                                <p>
                                                                    Right Header</p>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                <tr id="trMenubar" valign="top">
                                    <td>
                                        <ul id="menu">
                                            <li style="text-align: center;"><a href="#" class="drop">Home </a></li>
                                            <li style="text-align: center;"><a href="#" class="drop">About Us </a></li>
                                            <li style="text-align: center;"><a href="#" class="drop">Courses </a></li>
                                            <li style="text-align: center;"><a href="#" class="drop">Faculty </a></li>
                                            <li style="text-align: center;"><a href="#" class="drop">Online Admissions </a></li>
                                            <li style="text-align: center;"><a href="#" class="drop">Results </a></li>
                                            <li style="text-align: center"><a href="#" class="drop">Feed Back </a></li>
                                            <li style="text-align: center"><a href="#" class="drop">Contact Us </a></li>
                                        </ul>
                                    </td>
                                </tr>
                                <tr style="height: 150px; background-color: Aqua">
                                    <td>
                                        <p>
                                            Flash</p>
                                    </td>
                                </tr>
                                <tr id="trContent" class="ContentArea">
                                    <td>
                                        <div>
                                            <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                                            </asp:ContentPlaceHolder>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </td>
                        <td style="width: 5px;">
                        </td>
                    </tr>
                </table>
            </form>
        </div>
        <div>
            <table cellpadding="0" cellspacing="0" border="0" width="100%">
                <tr>
                    <td style="width: 5px;">
                    </td>
                    <td id="footer" valign="middle">
                        <strong>Copyright © 2011 Concept</strong>
                    </td>
                    <td style="width: 5px;">
                    </td>
                </tr>
            </table>
        </div>
    </div>
</body>