Saturday, 21 March 2015

Show PDF file In iframe using asp.net c#

HTML CODE

 <tr>
                <td style="height: 450px; width: 630px; background-color:azure">
                    <iframe width="630" height="840" id="displayRate" visible="false" runat="server"></iframe>
                </td>

            </tr>


C# CODE

        if (DropDownList1.SelectedValue == "AIR")
        {
            if (DropDownList2.SelectedValue == "13")
            {
                displayRate.Visible = true;
                displayRate.Attributes["src"] = "plans/AIRCEL/Andhra_Pradesh_&_Telangana.htm";
            }
}

Friday, 27 February 2015

Image Slider using Repeater From Database Asp.Net

Default.Aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
      <div>
        <table>
            <tr>
                <td>ImageName:-</td>
                <td>
                    <asp:TextBox ID="TextBox1" runat="server" Height="31px" Width="274px"></asp:TextBox></td>
            </tr>
             <tr>
                <td>Description:-</td>
                <td>
                    <asp:TextBox ID="TextBox2" runat="server" Height="31px" Width="276px"></asp:TextBox></td>
            </tr>
               <tr>
                    <td>Photo:-</td>
                    <td>
                        <asp:FileUpload ID="FileUpload1" runat="server" Height="33px" Style="font-weight: 700; color: #00CC00; text-align: left;" Width="282px"  /></td>
                    <td></td>
                    <td>
                        <asp:Button ID="Button1" runat="server" Text="Upload" Height="45px" Style="font-weight: 700; color: #CC0099" Width="91px" OnClick="Button1_Click" /></td>
                </tr>
       
                     </table>
          <asp:Label ID="Label1" runat="server" ></asp:Label>
          <br />
        <br />
            <asp:DataList ID="DataList1" runat="server" RepeatColumns="4" OnDeleteCommand="DataList1_DeleteCommand">
                <ItemTemplate>
                    <asp:Image ID="Image1" runat="server" Height="200" Width="200" ImageUrl='<%# "ImagHand.aspx?id=" + Eval("id") %>' />
                                        <br />
                    <asp:Label ID="Label2" runat="server" Text='<%#Eval("ImageName") %>'></asp:Label>
                    <br />
                    <asp:Label ID="Label3" runat="server" Text='<%#Eval("ImageDescription") %>'></asp:Label>
                    <br />
                     <asp:LinkButton ID="LinkButton1" CommandName="Delete" CommandArgument='<%# Eval("id") %>' runat="server">Delete</asp:LinkButton>
                    <br />
                    <br />
                </ItemTemplate>
            </asp:DataList>
     
    </div>
    </form>
</body>
</html>


Default.aspx.cs


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

public partial class _Default : System.Web.UI.Page
{
    string cs = ConfigurationManager.ConnectionStrings["news"].ConnectionString;
    string id;
    string FileName;
    Stream str;
    BinaryReader br;
    Byte[] size;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bindDatalist();
        }
    }

    private void bindDatalist()
    {
        using (SqlConnection con = new SqlConnection(cs))
        {
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.CommandText = "Select * From NewsSlid";
                cmd.Connection = con;
                con.Open();
                DataList1.DataSource = cmd.ExecuteReader();
                DataList1.DataBind();
                con.Close();//        
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string FileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
        Stream str = FileUpload1.PostedFile.InputStream;
        BinaryReader br = new BinaryReader(str);
        Byte[] size = br.ReadBytes((int)str.Length);
        string constr = ConfigurationManager.ConnectionStrings["news"].ConnectionString;
        using (SqlConnection con = new SqlConnection(constr))
        {
            string query = "insert into NewsSlid values (@ImageName,@ImageDescription,@FileName, @FileType,@ImagePath)";
            using (SqlCommand cmd = new SqlCommand(query))
            {
                cmd.Connection = con;
                cmd.Parameters.AddWithValue("@ImageName", SqlDbType.VarChar).Value = TextBox1.Text;
                cmd.Parameters.AddWithValue("@ImageDescription", SqlDbType.VarChar).Value = TextBox2.Text;
                cmd.Parameters.AddWithValue("@FileName", FileName);
                cmd.Parameters.AddWithValue("@FileType", "word/Application");
                cmd.Parameters.AddWithValue("@ImagePath", size);
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
                Label1.Visible = true;
                Label1.Text = "Data Uploaded";
                Label1.ForeColor = System.Drawing.Color.Yellow;




                Label1.Visible = true;
                Label1.Text = "Please select image file jpg or gif only";
                Label1.ForeColor = System.Drawing.Color.White;
            }

        }
        Response.Redirect(Request.Url.AbsoluteUri);
    }
    protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {
            id = e.CommandArgument.ToString();
            SqlConnection con = new SqlConnection(cs);
            SqlCommand cmd = new SqlCommand("delete from NewsSlid where id='" + id + "'", con);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            Response.Redirect("Default.aspx");
        }
    }
}


ImagHand.aspx.cs


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

public partial class ImagHand : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string id = Request.QueryString["id"];
        string cs = ConfigurationManager.ConnectionStrings["news"].ConnectionString;
        string query = "select ImagePath from NewsSlid where id=@id";
        SqlConnection con = new SqlConnection(cs);
        SqlCommand cmd = new SqlCommand(query, con);
        cmd.Parameters.Add("@id", SqlDbType.Int).Value = Convert.ToInt32(id);
        con.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        {
            if (dr.Read())
            {
                byte[] imgdata = (byte[])dr["ImagePath"];
                Response.BinaryWrite(imgdata);
                con.Close();
            }
        }
    }
}


Slider.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NewsSlider.aspx.cs" Inherits="NewsSlider" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link type="text/css" rel="stylesheet" href="js/view.css" /> 
    <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script> 
    <script type="text/javascript" src="js/jquery.easing.1.3.js"></script> 
    <script type="text/javascript" src="js/jquery-galleryview-1.1/jquery.galleryview-1.1.js"></script> 
    <script type="text/javascript" src="js/jquery-galleryview-1.1/jquery.timers-1.1.2.js"></script> 
    <script type="text/javascript">
        $(document).ready(function () {
            $('#photos').galleryView({
                panel_width: 800,
                panel_height: 350,
                frame_width: 80,
                frame_height: 80,
                nav_theme: 'custom'
            });
        });
</script> 
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:news %>" 
            SelectCommand="SELECT * FROM [NewsSlid]"></asp:SqlDataSource>
        <br />

        <!-- Main Strip to display focused Image Details. -->
        <div id="photos" class="galleryview">
        <asp:Repeater ID="Repeater2" runat="server" DataSourceID="SqlDataSource1">
        <ItemTemplate>
          <div class="panel"> 
                                   <asp:Image ID="Image1" Width="800" Height="350" runat="server" ImageUrl='<%# "ImagHand.aspx?id=" + Eval("id") %>' />
                <div class="panel-overlay"> 
                    <h2><%# Eval("ImageName") %></h2> 
                    <p>Description: <b><%# Eval("ImageDescription") %></b><br />  View full-size photo 
                                    <a href='<%# "ImagHand.aspx?id=" + Eval("id") %>' target="_blank">here</a>.</p> 
                </div> 
                </div>
        </ItemTemplate>
        </asp:Repeater>
        
        <!-- Strip to display the bottom slideshow. -->
        <ul class="filmstrip">
        <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
        <ItemTemplate>
            <li><img width="80" height="80" src='<%# "ImagHand.aspx?id=" + Eval("id") %>' 
                     alt='<%#Eval("ImageDescription") %>' title='<%# Eval("ImageName") %>' /></li>
        </ItemTemplate>
        </asp:Repeater>
        </ul>
        </div>
    </div>
    </form>
</body>
</html>

Wednesday, 25 February 2015

Email Sending Code Form Server Side Asp.net

Email  Sending Code Form Server Side Asp.net

using System;
using System.Collections.Generic;
using System.Web;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;

public partial class MAil : System.Web.UI.Page
{
 protected void Page_Load(object sender, EventArgs e)
    {

     }
 protected void btnSubmit_Click(object sender, EventArgs e)
    {
        #region Remotehost


        //--------FOR REMOTE HOST
        try
        {
            if (Page.IsValid)
            {

                const string SERVER = "localhost";
                MailMessage oMail = new MailMessage();
                oMail.From = new MailAddress("contact@mail.co");
                oMail.To.Add(new MailAddress("do_not_reply@mail.co"));
                oMail.Subject = TextBox2.Text;
                oMail.IsBodyHtml = true; // enumeration
                oMail.Priority = MailPriority.High; // enumeration
                oMail.Body = "<b>Sender's Name:-</b></b>" + TextBox1.Text + "<br/></b>" + "<b>Sender's Email:-</b></b>" + TextBox2.Text + "</b><br/>" + "<b>Sender's Mobile:-</b></b>" + TextBox3.Text + "</b><br/>" + "<b> Sender's Subject:-</b></b>" + DropDownList1.SelectedValue + "<br/></b>" + "<b>Sender's Message:-</b></b>" + TextBox4.Text + "<br/></b>" + "<b>Others:-</b></b>" + TextBox6.Text;
                SmtpClient sC = new SmtpClient(SERVER);
                sC.EnableSsl = false;
                ContentType contentType = new ContentType();
                contentType.MediaType = MediaTypeNames.Application.Octet;
                contentType.Name = "xml.xml";
                sC.Send(oMail);
                oMail = null; // free up resources
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('EMail Sent');", true);


                TextBox1.Enabled = false;
                TextBox2.Enabled = false;
                TextBox3.Enabled = false;
                TextBox4.Enabled = false;

            }


            TextBox1.Text = "";
            TextBox2.Text = "";
            TextBox3.Text = "";
            TextBox4.Text = "";

        }
        catch (Exception ex)
        {
            ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Error Found');", true);

        }
    }

Tuesday, 24 February 2015

Insert Data into Database in Binary From Using Handler

Database

Create table BinaryData
(
id int identity(1,1)primary key,
FileName Varchar(100),
FileType Varchar(100),
FileData Varchar(100)
)


Default.aspx......

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div style="height:500px; width:350px; background-color:wheat;">
   
        <br />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <asp:Button ID="Button1" runat="server" Text="Upload" OnClick="Button1_Click" />
    <asp:DataList ID="DataList1" runat="server" RepeatColumns="5">
        <ItemTemplate>
            <asp:Image ID="Image1" Height="200" Width="200" runat="server" ImageUrl='<%#"Handler.aspx?id="+ Eval("id") %>' />
        </ItemTemplate>
    </asp:DataList>
    </div>
    </form>
</body>
</html>


Default.aspx.cs

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

public partial class _Default : System.Web.UI.Page
{
    string cs = ConfigurationManager.ConnectionStrings["braj"].ConnectionString;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
       
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
      string FileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
        Stream str = FileUpload1.PostedFile.InputStream;
        BinaryReader br = new BinaryReader(str);
        Byte[] size = br.ReadBytes((int)str.Length);
        string constr = ConfigurationManager.ConnectionStrings["shopin"].ConnectionString;
        using (SqlConnection con = new SqlConnection(constr))
        {
            string query = "insert into BinaryData values (@FileName, @FileType,@FileData)";
            using (SqlCommand cmd = new SqlCommand(query))
            {
                cmd.Connection = con;
                cmd.Parameters.AddWithValue("@FileName", FileName);
                cmd.Parameters.AddWithValue("@FileType", "word/Application");
                cmd.Parameters.AddWithValue("@FileData", size);


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

Handler.aspx.cs..

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

public partial class Handler : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string id = Request.QueryString["id"];
        string cs = ConfigurationManager.ConnectionStrings["braj"].ConnectionString;
        string query = "select FileData from [BinaryData] where id=@id";
        SqlConnection con = new SqlConnection(cs);
        SqlCommand cmd = new SqlCommand(query, con);
        cmd.Parameters.Add("@id", SqlDbType.Int).Value = Convert.ToInt32(id);
        con.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        {
            if (dr.Read())
            {
                byte[] imgdata = (byte[])dr["FileData"];
                Response.BinaryWrite(imgdata);
                con.Close();
            }
        }
    }
}

web.config....

<?xml version="1.0"?>

<configuration>

    <system.web>
      <compilation debug="true" targetFramework="4.0" />
    </system.web>
  <connectionStrings>
    <add name="braj" connectionString="Data Source=.;Initial Catalog=MultipleIMG;Integrated Security=True" providerName=".NET Framework Data Provider for SQL Server"/>
  </connectionStrings>
</configuration>

Friday, 13 February 2015

How To Pass values One webpage to another webpage


SourcePage:-

 protected void btnCheckOut_Click(object sender, EventArgs e)
    {
        string PriceTotal = Txtsum.Text.Trim
            ();
        Session["PriceTotal"] = PriceTotal;
        string TotalItems = TextBox1.Text.Trim();
        Session["TotalItems"] = TotalItems;
        Response.Redirect("paymentgateway/pay.aspx");
}


Destination Page:-

 protected void Page_Load(object sender, EventArgs e)
    {
        TextBox1.Text = Session["PriceTotal"].ToString();
        TextBox2.Text = Session["TotalItems"].ToString();
     
    }