Tuesday, 19 June 2018

Image Save

 if (fuimage.HasFile)
            {
                string[] allowed_extensions = { "jpg", "png", "gif", "bmp" };
                string[] file_extension = fuimage.PostedFile.FileName.Split('.');
                string Result = "0";
                for (var i = 0; i <= allowed_extensions.Length - 1; i++)
                {
                    if (allowed_extensions[i].ToString() == file_extension[1].ToString())
                    {
                        Result = "1";
                    }
                }
                if (Result.Equals("1"))
                {
                    // string FileName= DateTime.Now.ToString("ddMMyyyyhhmmss") + "." + file_extension[1].ToString();
                    string FileName = DateTime.Now.ToString("ddMMyyyhhmmssffff") + "." + file_extension[1].ToString();
                    // string FileName = DateTime.Now.ToString("ddMMyyyyhhmmss") + "_" + f1Big.PostedFile.FileName;
                    string Pathh = "Images/" +FileName;
                    //string Pathh = "~/imgproduct/" + FileName;
                    fuimage.SaveAs(HttpContext.Current.Server.MapPath(Pathh));
                    fuimage.Visible = true;
                    imgLogo.ImageUrl = Pathh;
                    hdnlogopath.Value = Pathh.ToString();
                   
                }
                else
                {
                    ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Invalid File Please Choose jpg, png or  gif File   !');", true);
                    imgLogo.ImageUrl = "";
                    //hdnlogopath.Value = "0";
                }

Calender Extender

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %> 
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
     <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
        <tr>
            <td>Name</td><td><asp:TextBox ID="txtname" runat="server"></asp:TextBox></td>
        </tr>
        <tr>
            <td>Addres</td><td><asp:TextBox ID="txtaddress" runat="server"></asp:TextBox></td>
        </tr>
        <tr>
            <td>Dob</td>
            <td>
                <cc1:ToolkitScriptManager ID="toolScriptManageer1" runat="server"></cc1:ToolkitScriptManager> 
                
                    <asp:TextBox ID="txtDOB" runat="server"></asp:TextBox> 
                    <cc1:CalendarExtender ID="Calendar1" PopupButtonID="imgPopup" runat="server" TargetControlID="txtDOB" Format="dd/MM/yyyy" > </cc1:CalendarExtender> 
            </td>
        </tr>
      

Friday, 6 April 2018

Gmail Font, GoogleFont



 Gmail Font

@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 100;
  src: local('Roboto Thin'), local('Roboto-Thin'), url(//fonts.gstatic.com/s/roboto/v18/KFOkCnqEu92Fr1MmgVxFIzIFKw.woff2) format('woff2');
  unicode-range: U+0460-052F, U+1C80-1C88, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}

Monday, 20 March 2017

Future date not accept in asp.net


<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<script type="text/javascript">
function check_date()
{
var chkdate = document.getElementById("txtDate").value;

var edate = chkdate.split("/");
var spdate = new Date();
var sdd = spdate.getDate();
var smm = spdate.getMonth();
var syyyy = spdate.getFullYear();
var today = new Date(syyyy,smm,sdd).getTime();
var e_date = new Date(edate[2],edate[1]-1,edate[0]).getTime();
if(e_date > today)
 {
    alert("Date is not valid");
    return false;
 }
}
    </script>

onkeypress ="return check_date(event)" />

Thursday, 24 November 2016

hyperlink in image

<a href="BookCvDetails.aspx?adidd=4&ef=wqgs&adid=<%#Eval("Ac_Id") %>&xz3=fds6766 &ad=78"> <img alt="" src="images/search.png" /></a>

Email send

 protected void btnSubmit_Click(object sender, EventArgs e)
    {
        MailMessage msg;
        SqlCommand cmd = new SqlCommand();
        string ActivationUrl = string.Empty;
        string emailId = string.Empty;
        try
        {
            //SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["conStr"].ToString());
            //cmd = new SqlCommand("insert into Tb_Registration (Name,EmailId,Address,ContactNo) values (@Name,@EmailId,@Address,@ContactNo) ", con);
            //cmd.Parameters.AddWithValue("@Name", txtName.Text.Trim());
            //cmd.Parameters.AddWithValue("@EmailId", txtEmailId.Text.Trim());
            //cmd.Parameters.AddWithValue("@Address", txtAddress.Text.Trim());
            //cmd.Parameters.AddWithValue("@ContactNo", txtContactNo.Text.Trim());
            //if (con.State == ConnectionState.Closed)
            //{
            //    con.Open();
            //}
            //cmd.ExecuteNonQuery();
            //Sending activation link in the email
            msg = new MailMessage();
            SmtpClient smtp = new SmtpClient();
            emailId = txtEmailId.Text.Trim();
            //sender email address
            msg.From = new MailAddress("mohammed.akram52@gmail.com");
            //Receiver email address
            msg.To.Add(emailId);
            msg.Subject = "Confirmation email for account activation";
            //For testing replace the local host path with your lost host path and while making online replace with your website domain name
            ActivationUrl = Server.HtmlEncode("http://localhost:8665/MySampleApplication/ActivateAccount.aspx?UserID=" + FetchUserId(emailId) + "&EmailId=" + emailId);

            msg.Body = "Hi " + txtName.Text.Trim() + "!\n" +
                  "Thanks for showing interest and registring in <a href='http://www.webcodeexpert.com'> webcodeexpert.com<a> " +
                  " Please <a href='" + ActivationUrl + "'>click here to activate</a>  your account and enjoy our services. \nThanks!";
            msg.IsBodyHtml = true;
            smtp.Credentials = new NetworkCredential("mohammed.akram52@gmail.com", "saheenakram");
            smtp.Port = 587;
            smtp.Host = "smtp.gmail.com";
            smtp.EnableSsl = true;
            smtp.Send(msg);
            clear_controls();
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Confirmation Link to activate your account has been sent to your email address');", true);
        }
        catch (Exception ex)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
            return;
        }
        finally
        {
            ActivationUrl = string.Empty;
            emailId = string.Empty;
            con.Close();
            cmd.Dispose();
        }
    }
  

Insert image in binary format

.....................................................aspx....................................................................

<div>
     <fieldset style="width:400px;">
    <legend>Save and retrieve image from database</legend>
    <table>
    <tr><td>Book Name: </td><td><asp:TextBox ID="txtBookName" runat="server"></asp:TextBox></td>
        </tr>
    <tr><td>Author: </td><td><asp:TextBox ID="txtAuthor" runat="server"></asp:TextBox></td></tr>
    <tr><td>Publisher: </td><td><asp:TextBox ID="txtPublisher" runat="server"></asp:TextBox></td></tr>
    <tr><td>Price: </td><td><asp:TextBox ID="txtPrice" runat="server"></asp:TextBox></td></tr>
    <tr><td>Book Picture: </td><td>
        <asp:FileUpload ID="flupBookPic" runat="server" /></td></tr>
        <tr><td></td><td>
            <asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click" />
            <asp:Button ID="btnCancel" runat="server" onclick="btnCancel_Click"
                Text="Cancel" />
            </td></tr>
        <tr><td>&nbsp;</td><td>
            <asp:Label ID="lblStatus" runat="server"></asp:Label>          
            </td></tr>
      
        <tr><td colspan="2">
            <asp:GridView ID="grdBooks" runat="server" AutoGenerateColumns="false">
            <Columns>
            <asp:TemplateField>
            <ItemTemplate>
           <center>  <asp:Image ID="ImgBookPic" runat="server" Height="80px" Width="80px" /><br />
             <asp:Label ID="lblBookPicName" runat="server" Text='<%#Eval("BookPicName") %>'></asp:Label>
             </center>
            </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="BookName"  HeaderText="Book Name"  ItemStyle-HorizontalAlign="Center"/>
            <asp:BoundField DataField="Author"  HeaderText="Author" ItemStyle-HorizontalAlign="Center" />
            <asp:BoundField DataField="Publisher"  HeaderText="Publisher" ItemStyle-HorizontalAlign="Center" />
            <asp:BoundField DataField="Price"  HeaderText="Price" ItemStyle-HorizontalAlign="Center" />          
            </Columns>
            </asp:GridView>         
            </td></tr>
    </table> 
    </fieldset>
    </div>

................................................................cs   ................................................................................

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindGridView();
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        string fileName = string.Empty;
        string filePath = string.Empty;
        string getPath = string.Empty;
        string pathToStore = string.Empty;
        string finalPathToStore = string.Empty;
        Byte[] bytes;
        FileStream fs;
        BinaryReader br;
      
        SqlCommand cmd = new SqlCommand("InsertBookDetails_Sp", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@BookName", txtBookName.Text.Trim());
        cmd.Parameters.AddWithValue("@Author", txtAuthor.Text.Trim());
        cmd.Parameters.AddWithValue("@Publisher", txtPublisher.Text.Trim());
        cmd.Parameters.AddWithValue("@Price", Convert.ToDecimal(txtPrice.Text));

        try
        {
            if (flupBookPic.HasFile)
            {
                fileName = flupBookPic.FileName;
                filePath = Server.MapPath("BookPictures/" + System.Guid.NewGuid() + fileName);
                flupBookPic.SaveAs(filePath);

                fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                br = new BinaryReader(fs);
                bytes = br.ReadBytes(Convert.ToInt32(fs.Length));
                br.Close();
                fs.Close();

                cmd.Parameters.AddWithValue("@BookPic", bytes);
                cmd.Parameters.AddWithValue("@BookPicName", fileName);
                int getPos = filePath.LastIndexOf("\\");
                int len = filePath.Length;
                getPath = filePath.Substring(getPos, len - getPos);
                pathToStore = getPath.Remove(0, 1);
                finalPathToStore = "~/BookPictures/" + pathToStore;
                cmd.Parameters.AddWithValue("@BookPicPath", finalPathToStore);
            }
            con.Open();
            cmd.ExecuteNonQuery();
            lblStatus.Text = "Book Record saved successfully";
            lblStatus.ForeColor = System.Drawing.Color.Green;
            ClearControls();
            BindGridView();
        }
        catch (Exception ex)
        {
            lblStatus.Text = "Book Record could not be saved";
            lblStatus.ForeColor = System.Drawing.Color.Red;
        }
        finally
        {
            con.Close();
            cmd.Dispose();
            fileName = null;
            filePath = null;
            fs = null;
            br = null;
            getPath = null;
            pathToStore = null;
            finalPathToStore = null;
        }
    }
  
    private void BindGridView()
    {
        DataTable dt = new DataTable();
        byte[] bytes;
        string base64String = string.Empty;
        SqlCommand cmd = new SqlCommand("GetBookDetails_Sp", con);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter adp = new SqlDataAdapter(cmd);
        try
        {
            adp.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                grdBooks.DataSource = dt;
                grdBooks.DataBind();

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (!string.IsNullOrEmpty(Convert.ToString(dt.Rows[i]["BookPic"])))
                    {
                        bytes = (byte[])dt.Rows[i]["BookPic"];
                        base64String = Convert.ToBase64String(bytes, 0, bytes.Length);

                        Image img = (Image)grdBooks.Rows[i].FindControl("ImgBookPic");
                        img.ImageUrl = "data:image/png;base64," + base64String;
                    }
                }
           }
        }
        catch (Exception)
        {
            lblStatus.Text = "Book record could not be retrieved";
            lblStatus.ForeColor = System.Drawing.Color.Red;
        }
        finally
        {
            con.Close();
            dt.Clear();
            dt.Dispose();
            cmd.Dispose();
            bytes = null;
            base64String = null;
        }
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        ClearControls();
        lblStatus.Text = string.Empty;
    }

    private void ClearControls()
    {
        txtAuthor.Text = string.Empty;
        txtBookName.Text = string.Empty;
        txtPrice.Text = string.Empty;
        txtPublisher.Text = string.Empty;     
        txtBookName.Focus();
    }

..............................................sql..........................................................................................


talble

CREATE TABLE [dbo].[BookDetails](
    [BookID] [int] IDENTITY(1,1) NOT NULL,
    [BookName] [varchar](50) NULL,
    [Author] [varchar](50) NULL,
    [Publisher] [varchar](50) NULL,
    [Price] [decimal](18, 2) NULL,
    [BookPic] [varbinary](max) NULL,
    [BookPicName] [varchar](100) NULL,
    [BookPicPath] [varchar](200) NULL,

procedure


USE [Ekram]
GO
/****** Object:  StoredProcedure [dbo].[InsertBookDetails_Sp]    Script Date: 11/24/2016 22:30:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 ALTER PROCEDURE [dbo].[InsertBookDetails_Sp]
                @BookName                    VARCHAR(100),
                @Author                             VARCHAR(100),
                @Publisher                        VARCHAR(100),
                @Price                                 DECIMAL(18,2),            
                @BookPic                          VARBINARY(MAX)=NULL,
                @BookPicName              VARCHAR(100)=NULL,
                @BookPicPath                                VARCHAR(200)=NULL
AS
BEGIN
                SET NOCOUNT ON;
                INSERT INTO BookDetails(BookName,Author,Publisher,Price,BookPic,BookPicName,BookPicPath)
    VALUES (@BookName,@Author,@Publisher,@Price,@BookPic,@BookPicName,@BookPicPath)
END