Friday, 21 June 2013

How to add the Progress bar when u are Uplading a Video in asp.net

Programatically create buttons in code behind

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MultipleDynamicButtons.aspx.cs" Inherits="WebUI.Forums.MultipleDynamicButtons" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:PlaceHolder runat="server" ID="place" /><br />
        <asp:Literal runat="server" ID="lit" />
    </div>
    </form>
</body>
</html>
 
 
 
.CS Page
 
 
using System;
using System.Web.UI.WebControls;

namespace WebUI.Forums
{
    public partial class MultipleDynamicButtons : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            for (int i = 0; i < 3; i++)
   {
                Button btn = new Button();
                btn.ID = "Button" + i.ToString();
                btn.Text = "Test button" + i.ToString();
                btn.Click += new EventHandler(btn_Click);
                place.Controls.Add(btn);
   }
        }

        void btn_Click(object sender, EventArgs e)
        {
            lit.Text = string.Format("Button {0} was pressed.", ((Button)sender).ID);
        }
    }
} 

Friday, 14 June 2013

How to Bind the Gridview Vertically...

Hi All ,
I am mentioning the Code to bind the GrdiView in vartically...

<%@ Page Title="" Language="C#" MasterPageFile="~/master.master" AutoEventWireup="true" CodeFile="Testpage.aspx.cs" Inherits="Testpage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  
               
    <asp:GridView ID="GridView1" runat="server" ShowHeader="false" RowStyle-Wrap="true" Width="300px" GridLines="Both">

    </asp:GridView>
    
</asp:Content>


.CS page Code..
---------------------------
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;


public partial class Testpage : System.Web.UI.Page
{
 protected void Page_Load(object sender, EventArgs e)
 {
        if (!Page.IsPostBack)
        {
            BindGridView();
        }
 }
    private DataTable PivotTable(DataTable origTable)
    {

        DataTable newTable = new DataTable();
        DataRow dr = null;
        //Add Columns to new Table
        for (int i = 0; i <= origTable.Rows.Count; i++)
        {
            newTable.Columns.Add(new DataColumn(origTable.Columns[i].ColumnName, typeof(String)));
        }

        //Execute the Pivot Method
        for (int cols = 0; cols < origTable.Columns.Count; cols++)
        {
            dr = newTable.NewRow();
            for (int rows = 0; rows < origTable.Rows.Count; rows++)
            {
                if (rows < origTable.Columns.Count)
                {
                    dr[0] = origTable.Columns[cols].ColumnName; // Add the Column Name in the first Column
                    dr[rows + 1] = origTable.Rows[rows][cols];
                }
            }
            newTable.Rows.Add(dr); //add the DataRow to the new Table rows collection
        }
        return newTable;
    }

private void BindGridView()
{
        try
        {
            DataTable dt = Library.ExecuteQuery("select * from VipUsersInfo where VID=2");
            if (dt.Rows.Count > 0)
            {
                //Bind the First GridView with the original data from the DataTable
                //GridView1.DataSource = dt;
                //GridView1.DataBind();

                //Pivot the Original data from the DataTable by calling the
                //method PivotTable and pass the dt as the parameter

                DataTable pivotedTable = PivotTable(dt);
                GridView1.DataSource = pivotedTable;
                GridView1.DataBind();
            }
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Fetch Error:";
            msg += ex.Message;
            throw new Exception(msg);
        }
       
}


}


Thursday, 13 June 2013

How to get the Column list in sql srever

Hi ,


Try this ,You will get the Solution...........

SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'TableName' AND COLUMN_NAME not in('ColumnName1','ColumnName2')

Tuesday, 11 June 2013

How to Add strings of the Array in Single String


 string[] strarr = { opt1,opt2,opt3,opt4,opt5};
 for (int i = 0; i <= strarr.Length - 1; i++)
        {
            if (strarr[i] != "")
            {
                if (options == "")
                {
                    options = strarr[i];
                }
                else
                {
                    options += "," + strarr[i];
                }
            }
        }

Wednesday, 5 June 2013

Crop Image And Add water mark as a Image to image and Saved in Database and Filder also


Hello All,
I am mentioning here  the code to add watermark to the image Programmatically......You can use it.

  protected void btnupload_Click(object sender, EventArgs e)
    {
        String csName = "ButtonClickScript";
        Type csType = this.GetType();
        if (FileUpload1.HasFile)
        {
            try
            {
              
                string imageUrl = "~/UserImage/UserUploadImage/" + FileUpload1.PostedFile.FileName;
                //Fetching the image path of the Image that will be bind as Matermark
                string serverPath = HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath);
                string imageIconUrl = serverPath + "\\img\\watermarkimage.png";
  
                    //Get the location of the image
                    Image imagePhoto = Image.FromStream(FileUpload1.PostedFile.InputStream);

                    // Get dimensions of image
                    int imageHeight = imagePhoto.Height;
                    int imageWidth = imagePhoto.Width;

                    //Create a new Bitmap
                    Bitmap oBitmap = new Bitmap(imageWidth, imageHeight, PixelFormat.Format24bppRgb);

                    //Load Background Graphic from Image
                    Graphics oGraphics = Graphics.FromImage(oBitmap);
                    oGraphics.SmoothingMode = SmoothingMode.HighQuality;
                    oGraphics.DrawImage(imagePhoto, new Rectangle(0, 0, imageWidth, imageHeight), 0, 0, imageWidth, imageHeight, GraphicsUnit.Pixel);

                    //Layer 1: Add an Image Logo to the top left
                    if (!String.IsNullOrEmpty(imageIconUrl))
                    {
                        Image imageIcon = Image.FromFile(imageIconUrl);
                        oGraphics.DrawImage(imageIcon, new Rectangle(imageWidth-50, imageHeight-50, 35, 35), 0, 0, imageIcon.Width, imageIcon.Height, GraphicsUnit.Pixel);

                        imageIcon.Dispose();
                    }


   #region TO ADD THE TEXT AS WATER MARK
                    ////Layer 2: Add Comment
                    //if (!String.IsNullOrEmpty(imageComment))
                    //{
                    //    Font commentFont = new Font("Arial", 14, FontStyle.Regular); //Font Style
                    //    StringFormat commentFormat = new StringFormat();
                    //    commentFormat.Alignment = StringAlignment.Near; //Align text in left of layer

                    //    SolidBrush commentBrush = new SolidBrush(Color.Black); //Font Colour

                    //    oGraphics.FillRectangle(Brushes.Beige, 5, imageHeight - 55, imageWidth - 15, 50); //Create a rectangle with white background
                    //    oGraphics.DrawString(imageComment, commentFont, commentBrush, new Rectangle(5, imageHeight - 55, imageWidth - 15, 50), commentFormat); //Add comment text inside rectangle
                    //}

                    //Layer 3: Add Copyright watermark
                    //Font watermarkFont = new Font("Arial", 40, FontStyle.Bold); //Font Style
                    //SolidBrush semiTransBrush = new SolidBrush(Color.LightGray); //Font Colour
                    //StringFormat watermarkFormat = new StringFormat();
                    //watermarkFormat.Alignment = StringAlignment.Center; //Align text in center of image

                    //oGraphics.DrawString("Copyright",
                    //    watermarkFont,
                    //    semiTransBrush,
                    //    new PointF(imageWidth / 2, imageHeight / 2), watermarkFormat);
                    #endregion

                    //Dispose of graphic objects
                    imagePhoto.Dispose();
                    oGraphics.Dispose();

                    //Output image
                    string pageimageFolder = Server.MapPath(imageUrl);
                    if (File.Exists(pageimageFolder))
                    {
                        imageUrl = "";
                        imageUrl = "~/UserImage/" + DateTime.Now.Year + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + FileUpload1.FileName.ToString();
                        ////pageimageFolder = Server.MapPath(path);
                        oBitmap.Save(Server.MapPath(imageUrl));
                    }
                    oBitmap.Save(Server.MapPath(imageUrl));

                ClientScript.RegisterClientScriptBlock(csType, csName, "<script>alert('Image added successfully in the database and the folder!!!')</script>");
               
            }
            catch (Exception ex)
            {
                ClientScript.RegisterClientScriptBlock(csType, csName, "<script>alert('Some problem occured while adding the image!!! Please try again!!!')</script>");
                Response.Write(ex.Message);
            }
        }
    }