Thursday, August 30, 2018

GMAIL VERIFICATION LINK EMBED COAD

Move to Security Feature

Now click on Gmail Setting Feature, move to security feature or alternatively can hit/paste this URL in your browser 


where you can see settings. 

Access for less secure apps

  1. Turn off (default) 
  2. Turn On  tick karna hai

BULK EMAIL SENDING USING GRIDVIEW

using System;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Configuration;
usingSystem.Data.SqlClient;
usingSystem.Data;
usingSystem.Net.Mail;

publicpartialclassBulkmail : System.Web.UI.Page
{
SqlConnectioncn;
SqlCommand cm;
SqlDataReaderdr;
SqlDataAdapter ad;
protectedvoidPage_Load(object sender, EventArgs e)
    {
if (!IsPostBack)
        { }
    }
protectedvoidSend_Click(object sender, EventArgs e)
    {
String k = ConfigurationManager.AppSettings["my1"];
cn = newSqlConnection(k);
cn.Open();

foreach(GridViewRow r1 in GridView1.Rows)
        {
var ch1 = (CheckBox) r1.FindControl("ch");
if (ch1.Checked)
            {
StringfromEmail = "youremail";

// from/to/sub/body

MailMessagemailmassage = newMailMessage(fromEmail,r1.Cells[1].Text,"Welcome","This is testing msg");

mailmassage.Attachments.Add(newAttachment(FileUpload1.FileContent,System.IO.Path.GetFileName(FileUpload1.FileName)));
SmtpClientsmtpClient=  newSmtpClient("smtp.gmail.com", 587);
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = newSystem.Net.NetworkCredential(fromEmail, "PASSWORD");
try
        {
smtpClient.Send(mailmassage);
        }
catch(Exception ex)
        {
Response.Write(ex.Message);
        }
            }


        }

String i = "select * from bulkmail";
        cm = newSqlCommand(i, cn);
dr = cm.ExecuteReader();
        GridView1.DataSource = dr;
GridView1.DataBind();



    }
}

Thursday, August 23, 2018

send email local host and server

using System.Data.SqlClient;
using System.Configuration;
using System.Net.Mail;
using System.Data;
using System.Web.UI.HtmlControls;

public partial class mailtofrom : System.Web.UI.Page
{
    SqlConnection cn;
    SqlCommand cm;
    SqlDataAdapter adp;
    SqlDataReader dr;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        { }
    }
    protected void send_Click(object sender, EventArgs e)// sever code
    {
         // server code
          MailMessage mail = new MailMessage();//object created
        //Setting From , To and CC

        mail.To.Add(TextBox1.Text);
        mail.From=new MailAddress("email id ");
        mail.Subject="thanks for Registartion";
        mail.Body="I Am FINE";
        mail.IsBodyHtml=true;// it will convert msg format in html
        //smtp object

        SmtpClient smtp= new SmtpClient();
        smtp.Host="smtp.gmail.com";
        smtp.Credentials=new System.Net.NetworkCredential("email","pass");//email id & password
        smtp.EnableSsl=true;// server security licence will true then only mail will send
        smtp.Send(mail);//send function with mail object pass...which will send mail.
            }







    protected void SENDTO_Click(object sender, EventArgs e)// local data
    {
        // Local HOst
        string fromEmail = "email";
        MailMessage mailmessage = new MailMessage(fromEmail, TextBox1.Text, TextBox3.Text, TextBox2.Text);
        SmtpClient smtpclient = new SmtpClient("email",587);
        smtpclient.EnableSsl = true;
        smtpclient.UseDefaultCredentials = false;
        smtpclient.Credentials = new System.Net.NetworkCredential("email""pass");
        try
        {
            smtpclient.Send(mailmessage);
        }
        catch(Exception ex)
        {
            Response.Write(ex.Message);
        }

    }
}

Calculate Number of week between two days

Calculate  Number of  week  between two days

 void LeaveFunction()
    {


        int a, b, c;


        a = int.Parse(Label9.Text);

        // DateTime dateofleave = Convert.ToDateTime(TextBox1.Text, System.Globalization.CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat);

        DateTime dateofjoining = Convert.ToDateTime(Label8.Text, System.Globalization.CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat);
        //int i = dt1.Day - dt.Day;

        int numberOfWeeksOfService = NumberOfWeeks(dateofjoining, DateTime.Now);
        //  int numberOfWeeksBeforeLeave = NumberOfWeeks(DateTime.Now, dateofleave);
     
        Label10.Text = numberOfWeeksOfService.ToString();

        c = a + numberOfWeeksOfService;
        Response.Write(c.ToString());

        if (c == 1)
        {


        }
        else if (c == 2)
        {


        }
        else if (c == 3)
        {


        }
        else if (c == 4)
        {


        }
        else if (c == 5)
        {
            Response.Redirect("week5.aspx");

        }
        else
        {

            ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('week completed')", true);


        }





     

    }
    int NumberOfWeeks(DateTime dateFrom, DateTime dateTo)
    {
        TimeSpan Span = dateTo.Subtract(dateFrom);

        if (Span.Days <= 7)
        {
            if (dateFrom.DayOfWeek > dateTo.DayOfWeek)
            {
                return 2;
            }

            return 1;
        }

        int Days = Span.Days - 7 + (int)dateFrom.DayOfWeek;
        int WeekCount = 1;
        int DayCount = 0;

        for (WeekCount = 1; DayCount < Days; WeekCount++)
        {
            DayCount += 7;
        }

        return WeekCount;
    }

Thursday, August 16, 2018

Receptor image

 <img alt="" src='images/<%#Eval("pic") %>' height="50px" width="50px" />

Repeater control event handling


Set  control inside the Repeater

<asp:Repeater ID="Repeater1" runat="server"  OnItemCommand="Repeater1_ItemCommand">
   
<ItemTemplate>


     <label>
      Title :  <%# Eval("ptitle")%>
     </label>

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

  <asp:Label ID="Name1" runat="server" ForeColor="Red"  Font-Bold="true"

  Text='<%#Eval("name") %>'/>

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

    
 <asp:LinkButton ID="Link_like" runat="server" Text="Like" 

 CommandName="cmd_like"

  CommandArgument='<%# Eval("sno")%>' />


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


<asp:Button ID="Button3" runat="server" style="color: #FFFFFF; font-weight: 700; background-color: #336699" 
CommandArgument='<%# Eval("sno")%> CommandName="cmd_show" Text="Comment"/>



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

<asp:Panel ID="view1" runat="server">
</panel>


<img src='/portal/upload/<%# DataBinder.Eval(Container.DataItem, "pic") %>' alt=""  style="height:60px;width:50px;"/>
                                      


   
   <asp:LinkButton ID="btn_comment" runat="server" Text="View Comment"
   CommandName="cmd_comment" CommandArgument='<%# Eval("sno")%>' />


   <asp:LinkButton ID="Link_like" runat="server" Text="Like"                 CommandName="cmd_like"  CommandArgument='<%# Eval("sno")%>' />


 ========================================================================================


        Display  previous  and   next   record

  <input id="txtHidden" style="width: 28px" type="hidden" value="0" runat="server" />
               

   <asp:LinkButton ID="lnkBtnPrev" runat="server" Font-Underline="False"

    OnClick="lnkBtnPrev_Click" Font-Bold="True"><< Prev </asp:LinkButton>
             
                     
    <asp:LinkButton ID="lnkBtnNext" runat="server" Font-Underline="False"

     OnClick="lnkBtnNext_Click" Font-Bold="True">Next >></asp:LinkButton>




      How  to   get  control  value  from  Repeater Control


protected void showcomment()
    {
        string cs = ConfigurationManager.AppSettings["mydb"];
        cn17 = new SqlConnection(cs);
        cn17.Open();
        for (int i = 0; i < Repeater1.Items.Count; i++)
        {

            Label rec = Repeater1.Items[i].FindControl("lblcomment") as Label;

            Label lblike = Repeater1.Items[i].FindControl("lbllike") as Label;

            Label dispcomment = Repeater1.Items[i].FindControl("disp_comment") as Label;
            Label displike = Repeater1.Items[i].FindControl("disp_like") as Label;


            string k = "select count(recno) from ideacomment where recno='" + rec.Text + "'";
            cm17 = new SqlCommand(k, cn17);
            dispcomment.Text = cm17.ExecuteScalar().ToString();



           string k2 = "select count(recno) from idealike where recno='" + lblike.Text + "'";
            cm17 = new SqlCommand(k2, cn17);
            displike.Text = cm17.ExecuteScalar().ToString();

        }

    }


          How to use  Repeater   control event

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        string cs = ConfigurationManager.AppSettings["mydb"];

        if (e.CommandName == "cmd_show") // check command is cmd_delete
        {


            int CustomerID = Convert.ToInt32(e.CommandArgument);
            Label22.Text = CustomerID.ToString();
            cn17 = new SqlConnection(cs);
            cn17.Open();
            string k1 = "select * from  pidea where sno='" + Label22.Text + "'";
            cm17 = new SqlCommand(k1, cn17);
            dr17 = cm17.ExecuteReader();
            if (dr17.Read())
            {
                Label29.Text = dr17[8].ToString();


            }

            dr17.Close();

            // TextBox myTextBox = (TextBox)Repeater1.FindControl("TextBox1");

            TextBox TextBox1 = (TextBox)e.Item.FindControl("TextBox1");

 string k = "insert into ideacomment values('" + Label22.Text + "','" + Label24.Text + "','" + Label25.Text + "','" + Label29.Text + "','" + Label26.Text + "','" + TextBox1.Text + "','" + Label27.Text + "','" + Label28.Text + "')";


            cm17 = new SqlCommand(k, cn17);
            cm17.ExecuteNonQuery();
            Label29.Text = "";
            Label22.Text = "";
            TextBox1.Text = "";
            cn17.Close();
            showcomment();


         }




        if (e.CommandName == "cmd_comment") // check command is cmd_delete
        {

            Panel pan1 = (Panel)e.Item.FindControl("view1");
            Repeater rep1 = (Repeater)e.Item.FindControl("Repeater2");
            // pan1.Visible = true;
            int CustomerID = Convert.ToInt32(e.CommandArgument);
            Label30.Text = CustomerID.ToString();
            cn17 = new SqlConnection(cs);
            cn17.Open();
            DataTable dt = new DataTable();

            SqlDataAdapter adp = new SqlDataAdapter("SELECT * FROM ideacomment where recno='" + Label30.Text + "'", cn17);

            adp.Fill(dt);
            rep1.DataSource = dt;
            rep1.DataBind();
            cn17.Close();


        }


        if (e.CommandName == "cmd_like") // send like to
        {


            int CustomerID = Convert.ToInt32(e.CommandArgument);
            Label31.Text = CustomerID.ToString();
            cn17 = new SqlConnection(cs);
            cn17.Open();

            string k21 = "insert into idealike values('" + Label25.Text + "','" + Label26.Text + "','" + Label31.Text + "')";
            cm17 = new SqlCommand(k21, cn17);
            cm17.ExecuteNonQuery();
            Label31.Text = "";
            showcomment();

       }



  }

Wednesday, August 15, 2018

Repeater Control

Aspx  code source  

 <asp:Repeater ID="repearter" runat="server">
  <ItemTemplate>
                                 
 Title : <asp:Label ID="lblTitle" runat="server" Text='<%# Eval("Title") %>'></asp:Label> <br>
Description : <asp:Label ID="lblDiscription" runat="server" Text='<%# Eval("Description") %>'></asp:Label>
                                 
 </ItemTemplate>
                               
 </asp:Repeater>



c#  code 

protected void bindRepeater()
    {
        try
        {
            con.Open();
            cmd = new SqlCommand("select * from tbl_AddNews Order by Date desc",con);
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            repearter.DataSource = ds;
            repearter.DataBind();
            con.Close();
        }
        catch (Exception ex)
        {
           
        }

    }

Sunday, August 12, 2018

Query String

Button Click Event
Page1.aspx

Response.Redirect("Default3.aspx?roll=" + TextBox2.Text);



Page2.aspx
protected void Page_Load(object sender, EventArgs e)
    {
     

        if (Request.QueryString.Count > 0)
        {

            TextBox1.Text=Request.QueryString["roll"];

        }


    }

Connect Label on Gridview

 <asp:TemplateField HeaderText="Sno">
                                            <ItemTemplate>
                                                <%#Container.DataItemIndex+1 %>
                                            </ItemTemplate>
                                        </asp:TemplateField>






  <asp:TemplateField HeaderText="Areas">
                                            <ItemTemplate>
                                                <asp:Label runat="server" ID="lblGvPengumuman" Text='<%# bind("areas") %>'></asp:Label>
                                                <asp:Label runat="server" ID="Label1" Width="50PX"></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>

Export Gridview to Excel

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.IO;
using System.Web.UI.HtmlControls;



protected void Button2_Click(object sender, EventArgs e)
    {
        string attachment = "attachment; filename=PROJECTRRCREPORT.xls";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/ms-excel";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);
        // HttpContext.Current.Response.Write("<img src='http://ghrce.edu.in/pic/adminlogin.JPG'>");
        //HttpContext.Current.Response.Write("<br><br><br><br><br><br><br>");     
        HttpContext.Current.Response.Write("<br>");
        // Create a form to contain the grid
        HtmlForm frm = new HtmlForm();
        GridView2.Parent.Controls.Add(frm);
        frm.Attributes["runat"] = "server";
        frm.Controls.Add(GridView2);
        frm.RenderControl(htw);
        //GridView1.RenderControl(htw);
        Response.Write(sw.ToString());
        Response.End();
    }

Excel Data Base connection string

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data.OleDb;

public partial class excelprog : System.Web.UI.Page
{


    OleDbConnection cn;
    OleDbCommand cm;
    OleDbDataReader dr;

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {

        }


    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        String conStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("~/file/student.xls") + ";" + "Extended Properties=Excel 8.0;";
        OleDbConnection con = new OleDbConnection(conStr);
        con.Open();

        string k = "select * from [Sheet1$]";
        cm = new OleDbCommand(k, con);
        dr = cm.ExecuteReader();
        GridView2.DataSource = dr;
        GridView2.DataBind();

        dr.Close();


    }
    protected void Button2_Click(object sender, EventArgs e)
    {

        String conStr = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Server.MapPath("~/file/student.xls") + ";" + "Extended Properties=Excel 8.0;";
        OleDbConnection con = new OleDbConnection(conStr);
        con.Open();


        string k = "insert into [Sheet1$] values('" + TextBox1.Text + "','" + TextBox2.Text + "'," + TextBox3.Text + " ,'" + TextBox4.Text + "')";
        cm = new OleDbCommand(k, con);
        cm.ExecuteNonQuery();
        TextBox1.Text = "";


    }
}

Saturday, August 11, 2018

Display all table in listbox


    
Display all  table in listbox 

protected void Button4_Click(object sender, EventArgs e)
    {

        //R&D  DATABASE

        string cs1 = ConfigurationManager.AppSettings["mydatabase"];
        cn7 = new SqlConnection(cs1);
        cn7.Open();

        string k = "SELECT name FROM sysobjects WHERE xtype='U' ORDER BY name";
        cm7 = new SqlCommand(k, cn7);
        dr7 = cm7.ExecuteReader();
        ListBox1.DataSource = dr7;
        ListBox1.DataTextField = "name";
        ListBox1.DataBind();
        ListBox1.Items.Insert(0, "Select");
    }






    protected void Button6_Click(object sender, EventArgs e)
    {
        //RND FIND
        string cs1 = ConfigurationManager.AppSettings["mydatabase"];
        cn7 = new SqlConnection(cs1);
        cn7.Open();

        string k = "select * from" + " " + ListBox1.Text;
        cm7 = new SqlCommand(k, cn7);
        dr7 = cm7.ExecuteReader();

        GridView1.DataSource = dr7;
        GridView1.DataBind();
    }

Create Dynamic Table on Data Base


Create Dynamic Table on Data Base 


 protected void Button1_Click(object sender, EventArgs e)
    {
        string tbl = "demoTbl";

        con = new SqlConnection(conStr);

        string cmdStr = "create table " + TextBox1.Text.Trim() + "(" + TextBox2.Text.Trim() + " " + TextBox3.Text.Trim() + "(" + TextBox4.Text.Trim() + ")," + TextBox5.Text.Trim() + " " + TextBox6.Text.Trim() + "(" + TextBox4.Text.Trim() + "))";


        cmd = new SqlCommand(cmdStr, con);

        con.Open();
       
        cmd.ExecuteNonQuery();
        con.Close();

    }

Video Upload using Asp.net

Video Upload using Asp.net

<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
 
    <httpRuntime  executionTimeout="100"  maxRequestLength="8071" useFullyQualifiedRedirectUrl="false"  minFreeThreads="80"  minLocalRequestFreeThreads="40" appRequestQueueLimit="1000"/>

GRIDVIEW ON ROW DATA BOUND EVENT

 Database Create  Student : roll , name , city , cost  Fix 6 Value  in Database Record  ====================================================...