Thursday 20 February 2014

create database from script file

--> some time required when new user register on particular website that time
     create new database automatically  from script file.

--> script file:  script file is database creation  code you can create script file from your exist database using asp.net with c# code

    how to create script file , the step is following
    -->right click on your database (SQL server 2008 )
    -->select script database as
    -->select create and file to
    -->and open save as dialogue box set name and path where you want save this script file
    -->and click save
    -->then some process is done and  create script file in your download folder or where you set the path when open dialogue box

-->and you must be changes path in script file (open script file and remove or change the local computer path) other-wise your code  gives error

--> add following code in your code behind file

    -->required following namespace
------------------------------------------------------------------------------------------------
    using Microsoft.SqlServer.Management.Smo;
    using Microsoft.SqlServer.Management.Common;

    -->and create following function
------------------------------------------------------------------------------------------------
    public void CreateDatabaseFromScriptfile()
    {
     cn4 = new SqlConnection(@"Data Source=path\SQLEXPRESS,53286;Initial Catalog=databasename;User ID=sa;Password=pwd;");    //Connecrtion string
           string strdbname = "db_" + txtAccountName.Text; //this is for new databsase name
           FileInfo file = new FileInfo(Server.MapPath("Database_Code") + "\\" + "scriptFile.sql");
           //Here  path where your script file is store
           string strscript = file.OpenText().ReadToEnd();
           // in strscript string variable assign script code for replace the database name and execute server side
           string strupdatescript = strscript.Replace("[OldDatabaseName]", strdbname);
           // OldDatabaseName which is you set : when you create script file from which database , set this database name
           Server server = new Server(new ServerConnection(cn4));
           server.ConnectionContext.ExecuteNonQuery(strupdatescript);
          //this executed on server side and create new database , and this database name is value of strdbname

    }

--> above function take some more time for create new database on server side

--> and this function use on click event or any where which you want to

Calculate marksheet using JavaScript

--> Copy following code in your notepad file and save file name with .html
------------------------------------------------------------------------------------------------

<html>
    <head>
        <title>mark-sheet</title>
    <script >
    var s1,s2,s3,s4,s5,s6,s7,total,per,name,roll;
    roll=prompt("enter the student roll no");
    name=prompt("Enter the student name");
    s1=parseInt(prompt("enter subject1 mark    : " ));
    s2=parseInt(prompt("enter subject2 mark    : " ));
    s3=parseInt(prompt("enter subject3 mark    : " ));
    s4=parseInt(prompt("enter subject4 mark    : " ));
    s5=parseInt(prompt("enter subject5 mark    : " ));
    s6=parseInt(prompt("enter subject6 mark    : " ));
    s7=parseInt(prompt("enter subject7 mark    : " ));

    total=s1+s2+s3+s4+s5+s6+s7;
    per=total/7;

    document.write(" <h1>    <center>   MARKSHEET    </h1> </center>");
    document.write(" <hr color=red>   <hr color=red>  ");
    document.write("  <h3>Roll no          :  " + roll);
    document.write(" <br> Name          :  " + name  +"</h3>");
    document.write(" <hr color=black>");
       document.write(" <b> <br> &nbsp &nbsp &nbsp     Subject           &nbsp &nbsp&nbsp &nbsp Mark  </b>");

    document.write(" <br> &nbsp &nbsp &nbsp     Subject 1      &nbsp &nbsp&nbsp &nbsp     &nbsp &nbsp   " + s1);
    document.write(" <br> &nbsp &nbsp &nbsp     Subject 2        &nbsp &nbsp&nbsp &nbsp   &nbsp &nbsp   "  + s2);
    document.write(" <br> &nbsp &nbsp &nbsp     Subject 3      &nbsp &nbsp&nbsp &nbsp    &nbsp &nbsp   " + s3);
    document.write(" <br> &nbsp &nbsp &nbsp     Subject 4       &nbsp &nbsp&nbsp &nbsp   &nbsp &nbsp    " + s4);
    document.write(" <br> &nbsp &nbsp &nbsp     Subject 5       &nbsp &nbsp&nbsp &nbsp   &nbsp &nbsp   " + s5);
    document.write(" <br> &nbsp &nbsp &nbsp     Subject 6        &nbsp &nbsp&nbsp &nbsp   &nbsp &nbsp   " + s6);
    document.write(" <br> &nbsp &nbsp &nbsp     Subject 7        &nbsp &nbsp&nbsp &nbsp  &nbsp &nbsp    " + s7);
    if(s1<40 || s2<40 || s3<40 || s4<40 || s5<40 || s6<40 || s7<40)
    {
        document.write(" <hr color=black>");
        document.write("  Total               <b>:  " + total  +  "<br>");   
        document.write(" &nbsp &nbsp &nbsp&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp <font color=red  > <h3>Fail  </h3></font>");
    }
    else
    {
        document.write(" <hr color=black>");
        document.write("    Total               :  " + total);   
        document.write("   <br>  Percentage   :  " + per);   
        document.write("   <br> grade                      :");

        if(per>=70)
        {
            document.write("      <b>Districation");
        }
        else if(per >=60)
        {
            document.write("       <b>First class");
        }
        else if(per>=48)
        {
            document.write("       <b>Second class");
        }
        else
        {
            document.write("        <b>pass class");
        }            
    }
    document.write(" <hr color=red>   <hr color=red>  ");
    </script>
    </head>
        <body bgcolor=silver>
    </body>   </html>

--> then open this page in browser

background change when mouseover on button

-->Following code copy in your notepad and save file name with extension .html
------------------------------------------------------------------------------------------------

<html>
    <head>
        <title>Hitesh Kaklotar</title>
    <script>

        function red()
        {
            document.bgColor="red";
        }
        function g()
        {
            document.bgColor="green";
        }

        function b()
        {
            document.bgColor="blue";
        }

        function red()
        {
            document.bgColor="red";
        }

        function s()
        {
            document.bgColor="silver";
        }

        function y()
        {
            document.bgColor="yellow";
        }

        function m()
        {
            document.bgColor="maroon";
        }

        function p()
        {
            document.bgColor="pink";
        }
        function bl()
        {
            document.bgColor="black";
        }
        function w()
        {
            document.bgColor="white";
        }

    </script>
    <style type="text/css">
        .box
        {
            width:700px;
            padding:5px;
            border:5px solid black;
            margin:10px;
            background-color:white;

        }
        body
        {
            //background-color:silver;
            align:right;
            font-style:bold;
        }
        h3
        {
            background-color:silver;
            font-family:arial;
            text-align:right;   
            width:700px;       
            font-size:15px;   
        }
        a:hover
        {
            color:maroon;
            background-color:gray;
            font-family:verdana;
            color:blue;
        }
        #red:hover
        {
            background:red;
        }
        #g:hover
        {
            background:green;
        }
        #b:hover
        {
            background:blue;
        }
        #s:hover
        {
            background:silver;
        }
        #y:hover
        {
            background:yellow;
        }
        #m:hover
        {
            background:maroon;
        }
        #p:hover
        {
            background:pink;
        }
        #bl:hover
        {
            background:black;
        }
        #w:hover
        {
            background:white;
        }
    </style>
    </head>
    <body>
        <br><br>
        <div class="box">

        <h3>
        <a href=" ">Home</a> &nbsp &nbsp
        <a href=" ">Services</a> &nbsp &nbsp
        <a href=" ">About US</a> &nbsp &nbsp
        <a href=" ">Contact US</a> &nbsp &nbsp
        </h3>
        </div>

        <br>
        <input type="button" value="                 RED                          " id="red" OnmouseOver="red()" ><br><br>
        <input type="button" value="                 GREEN                     " id="g"   OnmouseOver="g()"><br><br>
        <input type="button" value="                 BLUE                        " id="b"   OnmouseOver="b()"><br><br>
        <input type="button" value="                 SILVER                     " id="s"  OnmouseOver="s()" ><br><br>
        <input type="button" value="                 YELLOW                  "id="y"   OnmouseOver="y()" ><br><br>
        <input type="button" value="                 MAROON                 " id="m" OnmouseOver="m()" ><br><br>
        <input type="button" value="                 PINK                         " id="p"  OnmouseOver="p()" ><br><br>
        <input type="button" value="                 BLACK                     " id="bl"  Onclick="bl()"><br><br>
        <input type="button" value="                 WHITE                     " id="w"  Onclick="w()" ><br><br>
        <br>       
    </body>
</html>

--> then open this page in your browser , and move mouse pointer on button then display effect
(change background)

------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------

Javascript complete validation form  : http://problemaspdotnet.blogspot.in/2014/02/javascript-basic-validation.html

Update progress example in asp.net

--> Page not refresh every time when get new data or fill data in datacontrol

-->if you want to create update progress in your web page for page is not refresh
after some event occurred like Click, CheckedChanged,SelectedIndexChanged.........
   
--> Then do following

---> following code add in your  source(.aspx file)
------------------------------------------------------------------------------------------------
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<asp:Button ID="btnSearch" runat="server" Text="Search"> </asp:Button>
<br>
<asp:UpdateProgress ID="updateProgress1" runat="server">
<ProgressTemplate>
 <div style="position: fixed; text-align: center; height: 100%; width: 100%; top: 0;
 right: 0; left: 0; z-index: 9999999; background-color: #000000; opacity: 0.7;">
<asp:Image ID="imgUpdateProgress" runat="server"
 ImageUrl="~/your ProgressBar image path/ProgressBar.gif"
 AlternateText="Filling Data ..." ToolTip="Filling Data ..." Style="padding: 10px; position: fixed;
 top: 35%; left: 45%;" />
</div>
</ProgressTemplate>
                </asp:UpdateProgress>
                <asp:UpdatePanel ID="up1" runat="server">
                    <Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" />
// In ControlID set your control's name     You can use more than one control event here  like following
<%--<asp:AsyncPostBackTrigger ControlID="ddlData" EventName="SelectedIndexChanged" />--%>
  <%--<asp:AsyncPostBackTrigger ControlID="rb3" EventName="CheckedChanged" />--%>
                    </Triggers>
                    <ContentTemplate>
    <asp:gridview ID=gvData runat="server"></asp:Gridview>
    //    Your Data control like Gridview ,ListView .......
    //    Or Table
   
     </ContentTemplate>
                </asp:UpdatePanel>

Modal-popup in asp.net

--> If you want to create a Ajax modal-popup in your website(As log in form) that time do following

-->First copy following css class in .aspx head tag
------------------------------------------------------------------------------------------------
<style type="text/css" >
            .modalBackground { 
            background-color:Black; 
            filter:alpha(opacity=70); 
            opacity:0.7; 
            } 
            .corner {
            -moz-border-radius: 10px;
            -webkit-border-radius: 10px;
            border-radius: 20px;
            }
           .roundedcorner
           {
            -moz-border-radius: 10px;
            -webkit-border-radius: 10px;
            border-radius: 20px;
          }
</style>

--> Next , Following code copy in your .aspx file
------------------------------------------------------------------------------------------------
<asp:Panel ID="pnlProject" runat="server" Width="500px" BackColor="White"
        CssClass="roundedcorner">
    <table  align="right" width="475px">
        <tr>
            <td colspan="3" align="right">
            <asp:ImageButton ID="ibClose" runat="server" CssClass="close"
            ImageUrl="~/Database_Code/x.png" />
            </td>
            <tr>
                <td colspan="3">
                        <h3>
                        <asp:Label ID="Label15" runat="server" Font-Names="Arial Narrow"
                            Text="Log In Here"></asp:Label>
                    </h3>
                </td>
            </tr>
            <tr>
            <td colspan="3">
                <hr color="Brown" />
            </td>
            </tr>
                <tr>
                <td>
                    <asp:Label ID="Label7" runat="server" Text="User Id"></asp:Label>
                </td>
                <td colspan="2">
                    <asp:TextBox ID="txtUser" runat="server"></asp:TextBox>
                </td>
            </tr>
     <tr>
                <td>
                    <asp:Label ID="Label7" runat="server" Text="Password"></asp:Label>
                </td>
                <td colspan="2">
                    <asp:TextBox ID="txtUserPws" TextMode="Password" runat="server"></asp:TextBox>
                </td>
            </tr>
    <tr>
                     <td colspan="3">
                    <asp:Button ID="btnLogin" Text="Log In" onclick="btnLogin_Click"  runat="server"></asp:TextBox>
                </td>
            </tr>
          
            <tr>
                <td colspan="2">
                    <hr color="Brown" />
                </td>
            </tr>

    </table>
    </asp:Panel>

<br />
        <asp:Button ID="btnProjInfo" Text="ok" runat="server" />

        <cc1:ModalPopupExtender ID="btnManageRole_ModalPopupExtender" runat="server" PopupControlID="pnlProject"
            CancelControlID="ibClose" BackgroundCssClass="modalBackground" DynamicServicePath=""
            Enabled="True" TargetControlID="btnProjInfo" />

--> when you click on log in button then display popup for log in .

AutoCompleteExtender example in asp.net with C#

or
Auto search example in asp.net

--> when type in the textbox then display search item in panel with mouse over effect
--> if you want to create auto complete or auto search functionality in your asp.net application that time do following

--> first you take textbox from toolbox in your page
------------------------------------------------------------------------------------------------
    Search :  <asp:TextBox ID="txtName" runat="server"  Width="300px"></asp:TextBox>

-->add AutoCompleteExtender control (if Ajax control toolkit add otherwise download Ajax control toolkit)   
--> next add following code in your source (.aspx) file
------------------------------------------------------------------------------------------------       
                 <cc1:autocompleteextender ID="AutoCompleteExtender1" runat="server"
                 CompletionInterval="10" Enabled="True" FirstRowSelected="True"
                 MinimumPrefixLength="1" ServiceMethod="getData"
                  TargetControlID="txtName"
                 UseContextKey="True"  CompletionListCssClass="AutoExtender"  // 3 css class define below
                 CompletionListItemCssClass="AutoExtenderList"
                 CompletionListHighlightedItemCssClass="AutoExtenderHighlight"
                 CompletionListElementID="divwidth">
                 </cc1:autocompleteextender>
//ServicePath="~/WebService.asmx"   
//this use when your function (here getData -web service) is another file or in .asmx file


--> next add following code in your source (.aspx) file in head section
------------------------------------------------------------------------------------------------
    <style type="text/css">
        .AutoExtender
        {
            font-family: Verdana, Helvetica, sans-serif;
            font-size: .9em;
            font-weight: normal;
            text-align:left;
            border: solid 1px #E5E5E5;
            line-height: 20px;
            padding: 1px;
            background-color: White;
            margin-left:1px;
            margin-top:0px;
        }
        .AutoExtenderList
        {
            border-bottom: none 1px #FFFFFF;
            cursor: pointer;
            color: Black;
        }
        .AutoExtenderHighlight
        {
            color: black;
            background-color: gray;
            cursor: pointer;
        }

</style>


next add this code or web service in code behind file
------------------------------------------------------------------------------------------------
    [System.Web.Script.Services.ScriptMethod()]
    [System.Web.Services.WebMethod]
    public static List<string> getData(string prefixText)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString()); //ConnectionString
        con.Open();
        SqlCommand cmd;
        cmd = new SqlCommand("select top(10) Id,Name from tbl_Student where Name like '" + prefixText + "%'", con);    //Your database table name and field name
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        List<string> Clientname = new List<string>();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            Clientname.Add("'" + dt.Rows[i]["Name"].ToString() + "'"); // this field fill when type in the textbox
        }
        con.Close();
        return Clientname;
    }

--> now run this page and type textbox then display list  item.

log in process code in asp.net

OR
User authenticate in asp.net

-->User authenticate required when Unauthorized user not access
some pages in your website

--> Table name  tbl_Student
--> field  (Id,Name,Address,.....User_Id,Password)
-->Add following namespace in your code behind file
------------------------------------------------------------------------------------------------
    using System.Data;
    using System.Data.SqlClient;

--> And then create following  object  above page load event
------------------------------------------------------------------------------------------------
    SqlConnection cn;
    SqlCommand cmd;
    SqlDataAdapter da;   
    DataSet ds;

--> Follwing code paste in your log_in button on click  event
------------------------------------------------------------------------------------------------

    cmd = new SqlCommand("select * from tbl_Student where
    User_Id=' "+txtUser.Text+" ' and Password=' "+txtPwd.Text+" ' ", cn);
    da = new SqlDataAdapter(cmd);
    ds = new DataSet();
    da.Fill(ds);
    if(ds.Tables[0].Rows.Count>0)
    {
        //when user id and password match then
        string Id=ds.Tables[0].Rows[0][0].ToString();
        Session["UserSession"]=Id;
         //Create session and use this session in entire application
        Response.Redirect("User/Home.aspx");
        //Successfully log in
    }
    else
    {
        //when user id and password does not match then
        Label1.Text="User name and Password does not match";
    }

Wednesday 19 February 2014

how to fetch data from the Excel file

 OR
how to get data from the Excel  file
-- > add name space in your code behind file

using System.IO;

--> next following code paste in your code behind file
------------------------------------------------------------------------------------------------
    StreamReader objReader;
    string fileExt = System.IO.Path.GetExtension("Your Excel file");
    //File name for get extension of the file
    if (fileExt == ".csv" || fileExt == ".CSV")
    {
    int linenum =0;
    objReader = new StreamReader(Server.MapPath("Your Excel file"));
    do
    {
                    textline = objReader.ReadLine();
                    if (textline != "")
                    {
                        string[] Data;
                        Data;= textline.Split(',');
                       // your Excel file in first row all data in array member by splite function

                       // You can split data in array like following changes

                         /* string[] data = line.Split('-');
                         string[] data = line.Split('/');
                         string[] data = line.Split('/');
                         string[] data = line.Split(' ');
                         string[] data = line.Split('Your specific character');   
                         */       
                      //now Your data in array and you use follows
         string code = data[0];
        string name = data[1];
        string date = data[2]; 

        // you can create sql query for insert above data (data[0],data[1]....) data in database
                        if (linenum == 0)
                        {
                         }
                        linenum++;//it is for change new line or next line in notepad file
                        }
                    }
                } while (objReader.Peek() != -1);// it is for end of the file
            }
            else //when file is not excel then message
            {
                Label1.Text="Select .CSV File only</span>";
            }

--> above function use on click event and fetch data from the Excel file

how to fetch data from the notepad file

OR
how to get data from the notepad file

--> create the function in your code behind file
------------------------------------------------------------------------------------------------
public Fetch_Data_From_Notapad()
{   
            string line = "";
 StreamReader streamReader = File.OpenText(Server.MapPath("notepad_file_path.txt"));
           do
            {
             line = streamReader.ReadLine();
            // it is for change new line or next line in notepad file
             string[] data = line.Split(';');
            // your notepad in first line's data in array member by splite function

    // You can splite data in array like following changes
    /* string[] data = line.Split('-');
     string[] data = line.Split('/');
     string[] data = line.Split('/');
     string[] data = line.Split(' ');
     string[] data = line.Split('Your specific character');   
    */
   
    //now Your data in array and you use follows
     string code = data[0];
    string name = data[1];
    string date = data[2];
             } while (streamReader.Peek() != -1); // it is for end of the file          
}

--> above function use on click event and fetch data from the notepad file

code for download notepad or txt file

--> if you want to download notepad file from the another website then
following code paste in your code behind file

-->Add namespace in your code behind file
-------------------------------------------------------------------------------------
    using System.IO;
    using System.Net;
    using System.Text;

-->next following code copy in your code behind file (.aspx.cs )
-------------------------------------------------------------------------------------
    WebClient client = new WebClient();
    string reply = client.DownloadString("path for you want to download file ");
    StringBuilder stringData = new StringBuilder();
    stringData.Append(reply);
    FileStream fs = new FileStream(@"Your path here :-where you store the file with file name", FileMode.Create);
    byte[] buffer = new byte[stringData.Length];
    for (int i = 0; i < stringData.Length; i++)
     {
         buffer[i] = (byte)stringData[i];
     }
    fs.Write(buffer,0, buffer.Length);
    fs.Close();

-->  above code use in your code behind on click event or
where you want to use

code for export data in MS-Word file

--> if you want to export data in word file from Gridview that time do following

--> Gridview name is gvProjects
--> create following function in your code behind file
------------------------------------------------------------------------------------------------

public void ExportData()
{
        Reponse.ClearContent();
        string FName = "filename.doc";
            mygrid.AllowPaging = false;
            mygrid.DataSource = datasource();
            mygrid.DataBind();
            Response.ClearContent();
            Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", FName));
            //set your download file name
            Response.Charset = "";
            Response.ContentType = "application/ms-word";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            mygrid.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();
          Response.Write(" \nProject Information \n \n");
            Response.Write("Project Name  \t   Project Start Date \t  Project End Date \t  Project Description \t \t \t Client Name");
            Response.Write("\n");
                     DataSet ds = new DataSet();
                     ds=FillGridview();
            for (int i = 0; i < gvProjects.Rows.Count; i++)
            {                 
Response.Write(ds.Tables[0].Rows[i]["Proj_Name"].ToString() + " \t  " + ds.Tables[0].Rows[i]["Proj_StartDate"].ToString() + " \t  " + ds.Tables[0].Rows[i]["Proj_EndDate"].ToString() + " \t  " + ds.Tables[0].Rows[i]["Proj_Desc"].ToString() + " \t \t \t " + ds.Tables[0].Rows[i]["Client_FullName"].ToString() );
    // above line change the filed name which is available in your table
         Response.Write("\n");
            }
        Response.End();*/
}


--> create following method for fill Gridview
 ------------------------------------------------------------------------------------------------

public void FillGridview()
{
    cmd = new SqlCommand("select * from Table_name", cn);
    da = new SqlDataAdapter(cmd);
    ds = new DataSet();
    da.Fill(ds);

    gvProjects.DataSource = ds;   //give dataset to gridview
    gvProjects.DataBind();         // binding gridview
   
}

--> above function use where you want to export data or Click event

how to export data in excel file

--> if you want to export data in excel file from Gridview that time do following

--> Gridview name is gvProjects
--> copy the following function in your code behind file
------------------------------------------------------------------------------------------------

public void ExportData()
{
        Reponse.ClearContent();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "AllProject.xls"));//set your download file name
        Response.ContentType = "application/ms-excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        Response.Write(sw.ToString());
        Response.Write(" \nProject Information \n \n");
        Response.Write("Project Name  \t   Project Start Date \t  Project End Date \t  Project Description \t \t \t Client Name");
        Response.Write("\n");
            DataSet ds = new DataSet();
            ds=FillGridview();
        for (int i = 0; i < gvProjects.Rows.Count; i++)
        {
           
            Response.Write(ds.Tables[0].Rows[i]["Proj_Name"].ToString() + " \t  " + ds.Tables[0].Rows[i]["Proj_StartDate"].ToString() + " \t  " + ds.Tables[0].Rows[i]["Proj_EndDate"].ToString() + " \t  " + ds.Tables[0].Rows[i]["Proj_Desc"].ToString() + " \t \t \t " + ds.Tables[0].Rows[i]["Client_FullName"].ToString() );
    // above line change the filed name which is available in your table
            Response.Write("\n");
        }
        Response.End();
}

--> create following method for fill Gridview

 ------------------------------------------------------------------------------------------------


public void FillGridview()

{
    cmd = new SqlCommand("select * from Table_name", cn);
    da = new SqlDataAdapter(cmd);
    ds = new DataSet();
    da.Fill(ds);

    gvProjects.DataSource = ds;   //give dataset to gridview
    gvProjects.DataBind();         // binding gridview
   
}

--> above function call where you want to export data

Tuesday 18 February 2014

code for send mail with HTML Body

--> if you want to send mail with HTML body and CSS class in asp.net using c# code then  do following

--> first import two namespace in code behind file(C # code file)

------------------------------------------------------------------------------------------------


using System.Net;

using System.Net.Mail;

--> next write following function in your code behind file
------------------------------------------------------------------------------------------------

 void SendMail()
    {
       String From, Recipients, smtpHost, port,amount,name;
        smtpHost = "0.0.0.0";// Your IP Address
        port = "25";
        From = "abc@xyz.com";   //From: address which account to you send mail
         Recipients = txtemail.Text;  // To: address where you send mail
        Subject = "send mail"; //  Your subject which is appear in recipients inbox
        string body = "<html><head>"+  //Your mail body with html tag and css class
 "<style> .Headerleft{width:50px; height:100px; float:left; }"+
 ".HeaderRight { width:250px; height:100px; float:right;}"+
".mainBody{width:700px;height:auto;float:left;margin-top: 20px;}"+
".Footer{width:165px;height:175px;float:right;  margin-top: 200px;aligne:Center;}"+
".temp{width:700px; height:450px;border:2px solid;border-radius:5px;padding: 10px 10px 50px;}"+
"hr{width:700;margin-top: 100px;}"+
"</style></head>"+
"<Title>asp.net with c#</title>"+
"<body ><div class='temp'><div><div class='Headerleft'>"+  
"<img src='image path'></img></div>"+
"<div class='HeaderRight'><b>Address:</b>"+
"<t>001,Wing 'C', Shreeji123 plaza,<br>&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp"+
" Anand Mahal Road, Adajan,<br> &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp Surat - 395009"+
"<br><b>Tel No</b>:0261-xxxxxx,4xxxxxx0</div></div>"+
"<hr><div class='mainBody'> &nbsp &nbsp &nbsp <br>Dear , <b>" + name + "</b>"+
"<br><br> &nbsp &nbsp &nbsp   ASp.net with C#...... ASp.net with C#......... ASp.net with C#."+
"....... ASp.net with C# ............<b>"+amount+",</b> -  ASp.net with C#...... ASp.net with C#........."+
"ASp.net with C#........ ASp.net with C# ............  ASp.net with C#...... ASp.net with C#........."+
" ASp.net with C#........ ASp.net with C# ............</div>" +
"<div class='Footer'><b>Thanks & Regards</b><br><br>Asp.net with C#.</div></div>"+
                        "</body></html>";

        MailMessage mailObj = new MailMessage(From, Recipients);//it is for From and To parameter.
        mailObj.Subject = subject;  //Your subject which is appear in recipients inbox
        mailObj.IsBodyHtml = true;  //this property true for html enable in mail
        mailObj.Body = body;  //  asigne  Your mail body for your message
        SmtpClient smtpClient = new SmtpClient(smtpHost, Convert.ToInt32(port));
        smtpClient.Credentials = new System.Net.NetworkCredential("abc@xyz.com", "abcxyz");
    // above line Your Mail Id and password
        smtpClient.Send(mailObj);
        }

--> this function call where you want to send mail

send mail(simple) in asp.net

if you want to send simple mail in asp.net using c# code then  do following

--> first import two namespace in code behind file(C # code file)
------------------------------------------------------------------------------------------------

using System.Net;
using System.Net.Mail;

--->next write following function in your code behind file
------------------------------------------------------------------------------------------------

 void SendMail()
    {
        String Subject, From, Recipients, Body, smtpHost, port;
        smtpHost = "0.0.0.0";   // Your IP  address
        port = "25";
        From = "abc@xyz.com";   //From : address which account to you send mail
        Recipients = abc123@yahoo.com;  // To : address where you send mail
        Subject = "send mail"; //  Your subject which is appear in recipients inbox
        Body = "";  //Your mail body your message
        MailMessage mailObj = new MailMessage(From, Recipients, Subject, Body);
        SmtpClient smtpClient = new SmtpClient(smtpHost, Convert.ToInt32(port));
        smtpClient.Credentials = new System.Net.NetworkCredential("abc@xyz.com", "abcxyz");
         //above line set Your Mail id and password
        smtpClient.Send(mailObj);
    }

--> this function use where you want to send Mail

Monday 17 February 2014

send SMS in asp.net

--> if you want to send sms using asp.net with c# code then do following
--> SMS service is not free , You must be purchase a SMS service pack from another company for send SMS

Other Articles - Step by step solution

------------------------------------------------------------------------
three tier architecture in asp.net
how to connect MS access in asp.net
how to access website in LAN
------------------------------------------------------------------------


--> Copy the following method in your code behind file


using System.Net;
using System.IO;


public void Send_SMS()
    {
        string username, Password, sender, to, message;
        //this all string variable contains Mobile No,Message
        WebClient client = new WebClient();
        string msg = "Thank you for visit Problemaspdotnet.blogspot.in blogs";
 string baseurl = " Your SMS provider link which Contains your   username,Password,sender,to,message....";
        WebRequest wrGETURL;
        StreamReader objReader;
        wrGETURL = WebRequest.Create(baseurl);
        try
        {
            Stream objStream;
            objStream = wrGETURL.GetResponse().GetResponseStream();
            objReader = new StreamReader(objStream);
            objReader.Close();
        }
        catch (Exception ex)
        {
            ex.ToString();
        }
    }

--> and above function use on click event or any where ,
      where you want to send SMS

Chart example in asp.net

--> if you want to create chart in asp.net from database data that time do following

--> Here table name tbl and field(Id,name,age)

-->copy following code in .aspx page
------------------------------------------------------------------------------------------------


<div>
Chart control in asp.net<br />
<br />
<asp:chart id="Chart5" runat="server" width="1000px" height="335px">
    <series>
        <asp:Series Name="age" XValueMember="name" YValueMembers="age" >
        </asp:Series>
<asp:Series Name="id" XValueMember="name" YValueMembers="id"></asp:Series>
    </series>
    <chartareas>
        <asp:ChartArea  Name="Age">
        </asp:ChartArea>
              
    </chartareas>
    <legends>
<asp:Legend Name="name" Title=" chart : Display age for particaular student"></asp:Legend>
    </legends>
</asp:chart>
</div>

--> Next , Copy the following code in your code behind file

--> add namespace
------------------------------------------------------------------------------------------------

  

using System.Data.SqlClient;
using System.Data;


--> create object above pageload event
------------------------------------------------------------------------------------------------

   

    SqlConnection cn;
    SqlCommand cmd;
    SqlDataAdapter da;
    DataSet ds;


--> Following code in your page load event
------------------------------------------------------------------------------------------------

 

cn = new SqlConnection(@"Data Source=YOUR CONNECTION STRING;Initial Catalog=student;Integrated Security=True");
        if (!IsPostBack)
        {
            disp();
        }


-->Create one method for get chart data
------------------------------------------------------------------------------------------------

  

public void disp()
    {
        cmd = new SqlCommand("select * from tbl", cn);
        da = new SqlDataAdapter(cmd);
        ds = new DataSet();
        da.Fill(ds);
        Chart5.DataSource = ds;// fill data in chart
        Chart5.DataBind();
    }


Asp.net tutorials