Please,Stay !

Good Morning friends…Image

windows forms validation for textbox to enter only numbers and only characters

//Allows only characters

private void txtName_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (Char.IsNumber(e.KeyChar) || Char.IsPunctuation(e.KeyChar))
            {
                MessageBox.Show(“Please Enter only Characters “);
                e.Handled = true;
            }

        }
//Allows only numbers
        private void txtPhone_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar >= 48 && e.KeyChar <= 57 || e.KeyChar == 46 || e.KeyChar == 8)
            {

                e.Handled = false;
            }

            else
            {
                MessageBox.Show(“Please Enter only Numbers”);
                e.Handled = true;
            }

        }

Windows forms Creating folder with given name in given directory

string folderName = Application.StartupPath + “\\Myfolder\\”;
            if (!Directory.Exists(folderName))
            {
                Directory.CreateDirectory(folderName);
            }

Click to learn more money

Click to learn more money

This is used to earn more money

Reaction of software guy when the error comes

Reaction of software guy when the error comes

Action and reaction

Developer’s site

Developer’s site

Its good site for all developers

Oka maranam

Its about life & death

Most Important Sites for .net

http://www.homeandlearn.co.uk/csharp/csharp_s11p1.html
msdn
csharp corner
stackoverflow
http://www.c-sharpcorner.com/
http://dotnetask.com/Resource.aspx?Resourceid=644
http://www.loginworks.com/technical-blogs/330-export-datagridview-to-excel

Asp.net send email using c#

Introduction:

In this article I will explain how to send email using asp.net.

Description:

In realtime we will use gmail,yahoo,hotmail etc to send mails to particular user here I will show to how to implement mail sending concept in asp.net.

To implement mail concept in asp.net first we need to add following reference to our application System.Web.Mail namespace 

What is System.Web.Mail

System.Web.Mail is a namespace which contains classes that enable us to construct and send messages using the CDOSYS (Collaboration Data Objects for Windows 2000) message component. The mail message is delivered either through the SMTP mail service built into Microsoft Windows 2000 or through an arbitrary SMTP server.

How we can get this reference (System.Web.Mail)

We need to add System.web.dll reference to our application for that follow below steps

a                 a)  On the Project menu, click Add Reference.
b)    On the .NET tab, locate System.Web.dll, and then click Select.
c)     Click OK in the Add References.
 

After that design your aspx page like this

<head runat=”server”>
<title>Send Mail using asp.net</title>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<table style=” border:1px solid” align=”center”>
<tr>
<td colspan=”2″ align=”center”>
<b>Send Mail using asp.net</b>
</td>
</tr>
<tr>
<td>
From:
</td>
<td>
<asp:TextBox ID=”txtFrom” runat=”server”></asp:TextBox>
</td>
</tr>
<tr>
<td>
Subject:
</td>
<td>
<asp:TextBox ID=”txtSubject” runat=”server”></asp:TextBox>
</td>
</tr>
<tr>
<td>
To:
</td>
<td>
<asp:TextBox ID=”txtTo” runat=”server”></asp:TextBox>
</td>
</tr>
<tr>
<td valign=”top”>
Body:
</td>
<td>
<asp:TextBox ID=”txtBody” runat=”server” TextMode=”MultiLine” Columns=”30″ Rows=”10″ ></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID=”btnSubmit” Text=”Send” runat=”server” onclick=”btnSubmit_Click” />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Now add following namcespaces in your codebehind
 

using System.Web.Mail;
After that write the following code in button click
 

protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
MailMessage Msg = new MailMessage();
// Sender e-mail address.
Msg.From = txtFrom.Text;
// Recipient e-mail address.
Msg.To = txtTo.Text;
Msg.Subject = txtSubject.Text;
Msg.Body = txtBody.Text;
// your remote SMTP server IP.
SmtpMail.SmtpServer = “10.20.72.1”;
SmtpMail.Send(Msg);
Msg = null;
Page.RegisterStartupScript(“UserMsg”, “<script>alert(‘Mail sent thank you…’);if(alert){ window.location=’SendMail.aspx’;}</script>”);
}
catch (Exception ex)
{
Console.WriteLine(“{0} Exception caught.”, ex);
}
}
Here use your SMTP server address then only it will work for you and check mails in spam also because sometimes mails should be appear in spam folder also.
Demo:
 

Creating setup file for .Net Windows application with icon & Uninstall:

Step1:

Create your application completely. (HMS)

Open solution Explorer,

Right Click on your solution name (HMS) àAddàNew Project

                                                                          àOther Project Types

                                                                                àSetup and DeploymentàVisual Studio Installer

                                                                                                                                               àSetup Project

Give the name of your setup and click OK (HMSSetup).

Step 2:

You will get File System (HMSSetup) Window:

From here select Application FolderàRight ClickàAddàProject Output

Add Project Output Group window will display:

                                         Here select   Project as: Your application name (HMS)

                                         Select Primary Output from below panelàClick OK.

Again Right click on Application FolderàAddàFile…

                                        (Here add files (or) images) select .ico icon for your applicationàclick on open.

From right side window select Primary OutputàRight ClickàCreate shortcut

Right Click on ShortcutàRename it as your application name (HMS).

Right Click on this shortcut (HMS) àProperties

                                            Icon: Browse

Here you will get a window, from this window double click on application folder select .ico iconàAdd iconàOK

Right click on shortcut (HMS) Cut.

From left side of window select User’s Desktop and Paste it (HMS) in right side window.

 

Step 3:

Create one .bat file for uninstall:

Select your setup name (HMSSetup) from solution exploreràpress F4 (Properties window)

Here copy product codeàProductCode: {BIOEBE……………………}

Create one notepad with name Uninstall.bat with text as below:

msiexec/x{BIOEBE………………}

Right click on Application FolderàAddàFileàRedirect to Uninstall.bat fileàselect Uninstall.batàopen

Right click on Application FolderàAddàFileàselect icon (.ico image) for uninstallàclick open

Right click on Uninstall.batàCreate short cutàRename it as Uninstall

Select Uninstall shortcutàproperties

                                            Icon: Browse

Here you will get a window from this window double click on application folder select .ico icon(uninstall icon)àAdd iconàOK

Step4:

Create one more HMS shortcut with icon same as above in step2.

Step5:

Select User’s Programs Menu from left side windowàRight clickàAddàFolder

Rename Folder same as application name (HMS).

Select Uninstall shortcut and HMS shortcutàright click Cut

Select HMS folder of User’s Programs MenuàPaste them in right side window.

Step6:

Go to Solution Exploreràselect your setup (HMSSetup)àpress F4(properties)

Author: Give the name for Folder in ProgrammFiles(To install your application in separate folder EX:Threshold Soft).

Manufacturer: Threshold Soft (same as above)

Product Name: your product name (Hotel Management system).

Step7:

Select your setup àRight click àBuild(HMSSetup).

Go to your application folder (HMS).

You can see your setup folder (HMSSetup).

Open setup folder (HMSSetup)àdebugàhere you will find setup files for your application

Double click on setup file to install.

After installation you will get your application icon (HMS) on your desktop.

Click on icon and check your application.

Go to start menuàAll Programsàyou will find HMSà Uninstall.