<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-9197207222512678697</id><updated>2012-02-16T05:23:51.513-08:00</updated><category term='Custom Control'/><category term='SQL SERVER'/><category term='Other'/><category term='Data Control'/><category term='Graphics GDI+'/><title type='text'>ASP.NET SOLUTIONS</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>21</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-7919155129686690805</id><published>2009-12-22T00:45:00.000-08:00</published><updated>2009-12-22T00:57:14.564-08:00</updated><title type='text'>Data Access Layer</title><content type='html'>&lt;span style="font-weight:bold;"&gt;SqlProvider static class&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Data.SqlClient;&lt;br /&gt;using System.Collections;&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// Data Access Layer&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;public static class SqlProvider&lt;br /&gt;{&lt;br /&gt;    // retrive connectio string from clsConnectionString class&lt;br /&gt;    public static string connectionString = clsConnectionString.conString;&lt;br /&gt;&lt;br /&gt;    // return parameter array&lt;br /&gt;    public static object[] returnParams = null;&lt;br /&gt;&lt;br /&gt;    // private static method&lt;br /&gt;    private static void AttachParameters(SqlCommand command, SqlParameter[] commandParameters)&lt;br /&gt;    {&lt;br /&gt;        foreach (SqlParameter p in commandParameters)&lt;br /&gt;        {&lt;br /&gt;&lt;br /&gt;            if ((p.Direction == ParameterDirection.InputOutput) &amp;&amp; (p.Value == null))&lt;br /&gt;            {&lt;br /&gt;                p.Value = DBNull.Value;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            command.Parameters.Add(p);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    private static void AssignParameterValues(SqlParameter[] commandParameters, object[] parameterValues)&lt;br /&gt;    {&lt;br /&gt;        if ((commandParameters == null) || (parameterValues == null))&lt;br /&gt;        {&lt;br /&gt;            return;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        //if (commandParameters.Length != parameterValues.Length)&lt;br /&gt;        //{&lt;br /&gt;        //    throw new ArgumentException("Parameter count does not match Parameter Value count.");&lt;br /&gt;        //}&lt;br /&gt;&lt;br /&gt;        for (int i = 0, j = parameterValues.Length; i &lt; j; i++)&lt;br /&gt;        {&lt;br /&gt;            if (commandParameters[i].Direction == ParameterDirection.InputOutput)&lt;br /&gt;            {&lt;br /&gt;                commandParameters[i].Value = "0";&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;            {&lt;br /&gt;                commandParameters[i].Value = parameterValues[i];&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    private static void PrepareCommand(SqlCommand command, SqlConnection connection, SqlTransaction transaction, CommandType commandType, string commandText, SqlParameter[] commandParameters)&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;        if (connection.State != ConnectionState.Open)&lt;br /&gt;        {&lt;br /&gt;            connection.Open();&lt;br /&gt;        }&lt;br /&gt;        command.Connection = connection;&lt;br /&gt;        command.CommandText = commandText;&lt;br /&gt;        if (transaction != null)&lt;br /&gt;        {&lt;br /&gt;            command.Transaction = transaction;&lt;br /&gt;        }&lt;br /&gt;        command.CommandType = commandType;&lt;br /&gt;        if (commandParameters != null)&lt;br /&gt;        {&lt;br /&gt;            AttachParameters(command, commandParameters);&lt;br /&gt;        }&lt;br /&gt;        return;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /// &lt;summary&gt;&lt;br /&gt;    /// Call Execute NonQuery Method :&lt;br /&gt;    /// Parameter : spName = Stored Procedure Name, Object[] = Array of stored procedure parameter &lt;br /&gt;    /// Return Parameter : (int)Nuber of affected row&lt;br /&gt;    /// &lt;/summary&gt;&lt;br /&gt;    /// &lt;param name="spName"&gt;&lt;/param&gt;&lt;br /&gt;    /// &lt;param name="parameterValues"&gt;&lt;/param&gt;&lt;br /&gt;    /// &lt;returns&gt;&lt;/returns&gt;&lt;br /&gt;    public static int ExecuteNonQuery(string spName, params object[] parameterValues)&lt;br /&gt;    {&lt;br /&gt;        if ((parameterValues != null) &amp;&amp; (parameterValues.Length &gt; 0))&lt;br /&gt;        {&lt;br /&gt;            SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(spName);&lt;br /&gt;            AssignParameterValues(commandParameters, parameterValues);&lt;br /&gt;            return ExecuteNonQuery(CommandType.StoredProcedure, spName, commandParameters);&lt;br /&gt;        }&lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            return ExecuteNonQuery(CommandType.StoredProcedure, spName);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    private static int ExecuteNonQuery(CommandType commandType, string commandText, params SqlParameter[] commandParameters)&lt;br /&gt;    {&lt;br /&gt;        using (SqlConnection cn = new SqlConnection(connectionString))&lt;br /&gt;        {&lt;br /&gt;            cn.Open();&lt;br /&gt;            return ExecuteNonQuery(cn, commandType, commandText, commandParameters);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    private static int ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;        SqlCommand cmd = new SqlCommand();&lt;br /&gt;        PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters);&lt;br /&gt;        int retval = cmd.ExecuteNonQuery();&lt;br /&gt;        cmd.Parameters.Clear();&lt;br /&gt;        return retval;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /// &lt;summary&gt;&lt;br /&gt;    /// Call Execute NonQuery Method :&lt;br /&gt;    /// Parameter : spName = Stored Procedure Name, outputparameterNames = Return parameter array, Object[] = Array of stored procedure parameter &lt;br /&gt;    /// Return Parameter : (object[])Return Parameter&lt;br /&gt;    /// &lt;/summary&gt;&lt;br /&gt;    /// &lt;param name="spName"&gt;&lt;/param&gt;&lt;br /&gt;    /// &lt;param name="parameterValues"&gt;&lt;/param&gt;&lt;br /&gt;    /// &lt;returns&gt;&lt;/returns&gt;&lt;br /&gt;    public static object[] ExecuteNonQuery(string spName, string[] outputparameterNames, params object[] parameterValues)&lt;br /&gt;    {&lt;br /&gt;        if ((parameterValues != null) &amp;&amp; (parameterValues.Length &gt; 0))&lt;br /&gt;        {&lt;br /&gt;            SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(spName);&lt;br /&gt;            AssignParameterValues(commandParameters, parameterValues);&lt;br /&gt;            return ExecuteNonQuery(CommandType.StoredProcedure, spName, outputparameterNames, commandParameters);&lt;br /&gt;        }&lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            return ExecuteNonQuery(CommandType.StoredProcedure, spName, outputparameterNames);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    private static object[] ExecuteNonQuery(CommandType commandType, string commandText, string[] outputparameterNames, params SqlParameter[] commandParameters)&lt;br /&gt;    {&lt;br /&gt;        using (SqlConnection cn = new SqlConnection(connectionString))&lt;br /&gt;        {&lt;br /&gt;            cn.Open();&lt;br /&gt;            return ExecuteNonQuery(cn, commandType, commandText, outputparameterNames, commandParameters);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    private static object[] ExecuteNonQuery(SqlConnection connection, CommandType commandType, string commandText, string[] outputparameterNames, params SqlParameter[] commandParameters)&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;        SqlCommand cmd = new SqlCommand();&lt;br /&gt;        PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters);&lt;br /&gt;        cmd.ExecuteNonQuery();&lt;br /&gt;        int i = 0;&lt;br /&gt;        returnParams = new object[outputparameterNames.Length];&lt;br /&gt;        foreach (string upParam in outputparameterNames)&lt;br /&gt;        {&lt;br /&gt;            returnParams[i] = cmd.Parameters[upParam].Value;&lt;br /&gt;            i++;&lt;br /&gt;        }&lt;br /&gt;        cmd.Parameters.Clear();&lt;br /&gt;        return returnParams;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /// &lt;summary&gt;&lt;br /&gt;    /// Call Execute Dataset Method :&lt;br /&gt;    /// Parameter : spName = Stored Procedure Name, Object[] = Array of stored procedure parameter &lt;br /&gt;    /// Return Parameter : (dataset)Operational Dataset&lt;br /&gt;    /// &lt;/summary&gt;&lt;br /&gt;    /// &lt;param name="spName"&gt;&lt;/param&gt;&lt;br /&gt;    /// &lt;param name="parameterValues"&gt;&lt;/param&gt;&lt;br /&gt;    /// &lt;returns&gt;&lt;/returns&gt;&lt;br /&gt;    public static DataSet ExecuteDataset(string spName, params object[] parameterValues)&lt;br /&gt;    {&lt;br /&gt;        if ((parameterValues != null) &amp;&amp; (parameterValues.Length &gt; 0))&lt;br /&gt;        {&lt;br /&gt;            SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(spName);&lt;br /&gt;            AssignParameterValues(commandParameters, parameterValues);&lt;br /&gt;            return ExecuteDataset(CommandType.StoredProcedure, spName, commandParameters);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            return ExecuteDataset(CommandType.StoredProcedure, spName);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    private static DataSet ExecuteDataset(CommandType commandType, string commandText, params SqlParameter[] commandParameters)&lt;br /&gt;    {&lt;br /&gt;        using (SqlConnection cn = new SqlConnection(connectionString))&lt;br /&gt;        {&lt;br /&gt;            cn.Open();&lt;br /&gt;            return ExecuteDataset(cn, commandType, commandText, commandParameters);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    private static DataSet ExecuteDataset(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)&lt;br /&gt;    {&lt;br /&gt;        SqlCommand cmd = new SqlCommand();&lt;br /&gt;        PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters);&lt;br /&gt;&lt;br /&gt;        SqlDataAdapter da = new SqlDataAdapter(cmd);&lt;br /&gt;        DataSet ds = new DataSet();&lt;br /&gt;        da.Fill(ds);&lt;br /&gt;        cmd.Parameters.Clear();&lt;br /&gt;        return ds;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /// &lt;summary&gt;&lt;br /&gt;    /// Call Execute Scalar Method:&lt;br /&gt;    /// Parameter : spName = Stored Procedure Name, Object[] = Array of stored procedure parameter &lt;br /&gt;    /// Return Parameter : (object)Signle row value&lt;br /&gt;    /// &lt;/summary&gt;&lt;br /&gt;    /// &lt;param name="spName"&gt;&lt;/param&gt;&lt;br /&gt;    /// &lt;param name="parameterValues"&gt;&lt;/param&gt;&lt;br /&gt;    /// &lt;returns&gt;&lt;/returns&gt;&lt;br /&gt;    public static object ExecuteScalar(string spName, params object[] parameterValues)&lt;br /&gt;    {&lt;br /&gt;        if ((parameterValues != null) &amp;&amp; (parameterValues.Length &gt; 0))&lt;br /&gt;        {&lt;br /&gt;            SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(spName);&lt;br /&gt;            AssignParameterValues(commandParameters, parameterValues);&lt;br /&gt;            return ExecuteScalar(CommandType.StoredProcedure, spName, commandParameters);&lt;br /&gt;        }&lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            return ExecuteScalar(CommandType.StoredProcedure, spName);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    private static object ExecuteScalar(CommandType commandType, string commandText, params SqlParameter[] commandParameters)&lt;br /&gt;    {&lt;br /&gt;        using (SqlConnection cn = new SqlConnection(connectionString))&lt;br /&gt;        {&lt;br /&gt;            cn.Open();&lt;br /&gt;&lt;br /&gt;            return ExecuteScalar(cn, commandType, commandText, commandParameters);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    private static object ExecuteScalar(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)&lt;br /&gt;    {&lt;br /&gt;        SqlCommand cmd = new SqlCommand();&lt;br /&gt;        PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters);&lt;br /&gt;&lt;br /&gt;        object retval = cmd.ExecuteScalar();&lt;br /&gt;&lt;br /&gt;        cmd.Parameters.Clear();&lt;br /&gt;        return retval;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    /// &lt;summary&gt;&lt;br /&gt;    /// Call Execute Reader Method:&lt;br /&gt;    /// Parameter : spName = Stored Procedure Name, Object[] = Array of stored procedure parameter &lt;br /&gt;    /// Return Parameter : (datareader)Operational Data Reader&lt;br /&gt;    /// &lt;/summary&gt;&lt;br /&gt;    /// &lt;param name="spName"&gt;&lt;/param&gt;&lt;br /&gt;    /// &lt;param name="parameterValues"&gt;&lt;/param&gt;&lt;br /&gt;    /// &lt;returns&gt;&lt;/returns&gt;&lt;br /&gt;    public static SqlDataReader ExecuteReader(string spName, params object[] parameterValues)&lt;br /&gt;    {&lt;br /&gt;        if ((parameterValues != null) &amp;&amp; (parameterValues.Length &gt; 0))&lt;br /&gt;        {&lt;br /&gt;            SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(spName);&lt;br /&gt;            AssignParameterValues(commandParameters, parameterValues);&lt;br /&gt;            return ExecuteReader(CommandType.StoredProcedure, spName, commandParameters);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            return ExecuteReader(CommandType.StoredProcedure, spName);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    private static SqlDataReader ExecuteReader(CommandType commandType, string commandText, params SqlParameter[] commandParameters)&lt;br /&gt;    {&lt;br /&gt;        SqlConnection cn = new SqlConnection(connectionString);&lt;br /&gt;&lt;br /&gt;        cn.Open();&lt;br /&gt;        return ExecuteReader(cn, commandType, commandText, commandParameters);&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;    private static SqlDataReader ExecuteReader(SqlConnection connection, CommandType commandType, string commandText, params SqlParameter[] commandParameters)&lt;br /&gt;    {&lt;br /&gt;        SqlCommand cmd = new SqlCommand();&lt;br /&gt;        try&lt;br /&gt;        {&lt;br /&gt;            PrepareCommand(cmd, connection, (SqlTransaction)null, commandType, commandText, commandParameters);&lt;br /&gt;            SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);&lt;br /&gt;            return reader;&lt;br /&gt;        }&lt;br /&gt;        finally { cmd.Parameters.Clear(); }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public sealed class SqlHelperParameterCache&lt;br /&gt;{&lt;br /&gt;    private SqlHelperParameterCache() { }&lt;br /&gt;    private static Hashtable paramCache = Hashtable.Synchronized(new Hashtable());&lt;br /&gt;    private static string connectionString = clsConnectionString.conString;&lt;br /&gt;    private static SqlParameter[] DiscoverSpParameterSet(string spName, bool includeReturnValueParameter)&lt;br /&gt;    {&lt;br /&gt;        using (SqlConnection cn = new SqlConnection(connectionString))&lt;br /&gt;        using (SqlCommand cmd = new SqlCommand(spName, cn))&lt;br /&gt;        {&lt;br /&gt;            cn.Open();&lt;br /&gt;            cmd.CommandType = CommandType.StoredProcedure;&lt;br /&gt;&lt;br /&gt;            SqlCommandBuilder.DeriveParameters(cmd);&lt;br /&gt;&lt;br /&gt;            //int c = cmd.Parameters.Count;&lt;br /&gt;            //for (int i = 0; i &lt; c; i++)&lt;br /&gt;            //{&lt;br /&gt;            //    if (cmd.Parameters[i].Direction == ParameterDirection.InputOutput)&lt;br /&gt;            //        cmd.Parameters.Remove(cmd.Parameters[i]);&lt;br /&gt;            //}&lt;br /&gt;            if (!includeReturnValueParameter)&lt;br /&gt;            {&lt;br /&gt;                cmd.Parameters.RemoveAt(0);&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            SqlParameter[] discoveredParameters = new SqlParameter[cmd.Parameters.Count];&lt;br /&gt;            cmd.Parameters.CopyTo(discoveredParameters, 0);&lt;br /&gt;&lt;br /&gt;            return discoveredParameters;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    private static SqlParameter[] CloneParameters(SqlParameter[] originalParameters)&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;        SqlParameter[] clonedParameters = new SqlParameter[originalParameters.Length];&lt;br /&gt;        for (int i = 0, j = originalParameters.Length; i &lt; j; i++)&lt;br /&gt;        {&lt;br /&gt;            clonedParameters[i] = (SqlParameter)((ICloneable)originalParameters[i]).Clone();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        return clonedParameters;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public static void CacheParameterSet(string commandText, params SqlParameter[] commandParameters)&lt;br /&gt;    {&lt;br /&gt;        string hashKey = connectionString + ":" + commandText;&lt;br /&gt;        paramCache[hashKey] = commandParameters;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public static SqlParameter[] GetCachedParameterSet(string commandText)&lt;br /&gt;    {&lt;br /&gt;        string hashKey = connectionString + ":" + commandText;&lt;br /&gt;        SqlParameter[] cachedParameters = (SqlParameter[])paramCache[hashKey];&lt;br /&gt;        if (cachedParameters == null)&lt;br /&gt;        {&lt;br /&gt;            return null;&lt;br /&gt;        }&lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            return CloneParameters(cachedParameters);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    public static SqlParameter[] GetSpParameterSet(string spName)&lt;br /&gt;    {&lt;br /&gt;        return GetSpParameterSet(spName, false);&lt;br /&gt;    }&lt;br /&gt;    public static SqlParameter[] GetSpParameterSet(string spName, bool includeReturnValueParameter)&lt;br /&gt;    {&lt;br /&gt;        string hashKey = connectionString + ":" + spName + (includeReturnValueParameter ? ":include ReturnValue Parameter" : "");&lt;br /&gt;        SqlParameter[] cachedParameters;&lt;br /&gt;        paramCache[hashKey] = null;&lt;br /&gt;        cachedParameters = (SqlParameter[])paramCache[hashKey];&lt;br /&gt;        if (cachedParameters == null)&lt;br /&gt;        {&lt;br /&gt;            cachedParameters = (SqlParameter[])(paramCache[hashKey] = DiscoverSpParameterSet(spName, includeReturnValueParameter));&lt;br /&gt;        }&lt;br /&gt;        return CloneParameters(cachedParameters);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;Connection String class.&lt;/span&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Configuration;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.Security;&lt;br /&gt;using System.Web.UI;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/// &lt;summary&gt;&lt;br /&gt;/// clsConnectionString class returns the connection string&lt;br /&gt;/// &lt;/summary&gt;&lt;br /&gt;public static class clsConnectionString&lt;br /&gt;{&lt;br /&gt;    public static string conString&lt;br /&gt;    {&lt;br /&gt;        get { return ConfigurationManager.AppSettings["conString"].ToString(); }&lt;br /&gt;    }&lt;br /&gt;   &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;How to call method&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1. Execute Non Query without input parameter and return parameter.&lt;br /&gt;public void Insert()&lt;br /&gt;        {&lt;br /&gt;            SqlProvider.ExecuteNonQuery("USP_ADMIN_LOG_INSERT");&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;2. Execute Non Query with input parameter and without return parameter.&lt;br /&gt;public void Insert()&lt;br /&gt;        {&lt;br /&gt;          SqlProvider.ExecuteNonQuery("USP_ADMIN_LOG_INSERT", this.ID,this.Name,......);&lt;br /&gt;//Input parameter is Property of the class.&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3. Execute Non Query with input paramter and return parameter.&lt;br /&gt;private Boolean Insert()&lt;br /&gt;        {&lt;br /&gt;            string[] OutParams = new string[1];&lt;br /&gt;            OutParams[0] = "@OutID"; -- this is out id variable that is define in stored procedure.&lt;br /&gt;            object[] outParam = SqlProvider.ExecuteNonQuery("USP_ADMIN_INSERTUPDATE",OutParams, this.ID);&lt;br /&gt;            if (outParam != null &amp;&amp; outParam.Length == 1)&lt;br /&gt;            {&lt;br /&gt;                this.OutID = Convert.ToInt32(outParam[0].ToString());&lt;br /&gt;                return true;&lt;br /&gt;                // this.OutID is property and outPram[0] returns return value from SP&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;                return false;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You can call Execute Dataset, Execute Scaler and Execute Reader same way.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-7919155129686690805?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/7919155129686690805/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=7919155129686690805' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/7919155129686690805'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/7919155129686690805'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2009/12/data-access-layer.html' title='Data Access Layer'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-1447723368216257339</id><published>2008-12-12T05:36:00.000-08:00</published><updated>2008-12-12T05:47:55.929-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Custom Control'/><title type='text'>Building Custom Control : Tell A Friend Custom Control</title><content type='html'>&lt;code&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.ComponentModel;&lt;br /&gt;using System.Text;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.UI;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;using System.Diagnostics;&lt;br /&gt;using System.IO;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Web.UI.Design;&lt;br /&gt;using System.Web.UI.HtmlControls;&lt;br /&gt;using System.Net.Mail;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;namespace ccc.TellaFriend&lt;br /&gt;{&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Create enum for Tellafriend Text&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public enum TellaFreindText&lt;br /&gt;{&lt;br /&gt;Your_Name=0,&lt;br /&gt;Your_Email=1,&lt;br /&gt;Friend_Email=2,&lt;br /&gt;Message=3,&lt;br /&gt;Button=4,&lt;br /&gt;Title=5&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Set control name&lt;br /&gt;&lt;code&gt;&lt;br /&gt;[DefaultProperty("Text"),&lt;br /&gt;ToolboxData("&lt;{0}:TellaFriend runat=server&gt;&lt;/{0}:TellaFriend&gt;"),&lt;br /&gt;Designer(typeof(ccc.TellaFriend.Design.TellaFriendDesing))]&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Class object with INamingContainer implementaion&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public class TellaFriend :System.Web.UI.WebControls.WebControl,INamingContainer&lt;br /&gt;{&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;create objects of the controls&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public Label lbl_title;&lt;br /&gt;&lt;br /&gt;public TextBox txt_yourname;&lt;br /&gt;public TextBox txt_yourEmail;&lt;br /&gt;public TextBox txt_friendEmail;&lt;br /&gt;public TextBox txt_message;&lt;br /&gt;&lt;br /&gt;public Button btn_send;&lt;br /&gt;&lt;br /&gt;public RequiredFieldValidator req1;&lt;br /&gt;public RequiredFieldValidator req2;&lt;br /&gt;public RequiredFieldValidator req3;&lt;br /&gt;public RequiredFieldValidator req4;&lt;br /&gt;&lt;br /&gt;public RegularExpressionValidator reg1;&lt;br /&gt;public RegularExpressionValidator reg2;&lt;br /&gt;&lt;br /&gt;public ValidationSummary vs;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Create Tell a Friend Text Property&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#region Tell a Friend Text&lt;br /&gt;&lt;br /&gt;[Bindable(true)]&lt;br /&gt;[Category("Appearance")]&lt;br /&gt;[DefaultValue("")]&lt;br /&gt;[Localizable(true)]&lt;br /&gt;&lt;br /&gt;public string Text&lt;br /&gt;{&lt;br /&gt;get&lt;br /&gt;{&lt;br /&gt;this.EnsureChildControls();&lt;br /&gt;string retVal = "";&lt;br /&gt;&lt;br /&gt;switch (TellaFreindText)&lt;br /&gt;{&lt;br /&gt;case TellaFreindText.Your_Name:&lt;br /&gt;retVal = txt_yourname.Text;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case TellaFreindText.Your_Email:&lt;br /&gt;retVal = txt_yourEmail.Text;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case TellaFreindText.Friend_Email:&lt;br /&gt;retVal = txt_friendEmail.Text;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case TellaFreindText.Message:&lt;br /&gt;retVal = txt_message.Text;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Button:&lt;br /&gt;retVal = btn_send.Text;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Title:&lt;br /&gt;retVal = lbl_title.Text;&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;return (retVal);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;set&lt;br /&gt;{&lt;br /&gt;this.EnsureChildControls();&lt;br /&gt;switch (TellaFreindText)&lt;br /&gt;{&lt;br /&gt;case TellaFreindText.Your_Name:&lt;br /&gt;txt_yourname.Text = value;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Your_Email:&lt;br /&gt;txt_yourEmail.Text = value;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Friend_Email:&lt;br /&gt;txt_friendEmail.Text = value;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Message:&lt;br /&gt;txt_message.Text = value;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Button:&lt;br /&gt;btn_send.Text = value;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Title:&lt;br /&gt;lbl_title.Text = value;&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;#endregion&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Create Tell a Friend CSS Property&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#region Tell a Freind CSS&lt;br /&gt;&lt;br /&gt;[Bindable(true)]&lt;br /&gt;[Category("Appearance")]&lt;br /&gt;[DefaultValue("")]&lt;br /&gt;[Localizable(true)]&lt;br /&gt;&lt;br /&gt;public string TellaFreindCss&lt;br /&gt;{&lt;br /&gt;get&lt;br /&gt;{&lt;br /&gt;this.EnsureChildControls();&lt;br /&gt;string retCss = "";&lt;br /&gt;&lt;br /&gt;switch (TellaFreindText)&lt;br /&gt;{&lt;br /&gt;case TellaFreindText.Your_Name:&lt;br /&gt;retCss = txt_yourname.CssClass;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case TellaFreindText.Your_Email:&lt;br /&gt;retCss = txt_yourEmail.CssClass;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case TellaFreindText.Friend_Email:&lt;br /&gt;retCss = txt_friendEmail.CssClass;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case TellaFreindText.Message:&lt;br /&gt;retCss = txt_message.CssClass;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Button:&lt;br /&gt;retCss = btn_send.CssClass;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Title:&lt;br /&gt;retCss = lbl_title.CssClass;&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;return (retCss);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;set&lt;br /&gt;{&lt;br /&gt;this.EnsureChildControls();&lt;br /&gt;switch (TellaFreindText)&lt;br /&gt;{&lt;br /&gt;case TellaFreindText.Your_Name:&lt;br /&gt;txt_yourname.CssClass = value;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Your_Email:&lt;br /&gt;txt_yourEmail.CssClass = value;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Friend_Email:&lt;br /&gt;txt_friendEmail.CssClass = value;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Message:&lt;br /&gt;txt_message.CssClass = value;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Button:&lt;br /&gt;btn_send.CssClass = value;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Title:&lt;br /&gt;lbl_title.CssClass = value;&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;#endregion&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Create Tell a Friend width and height Property&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#region Tell a Freind Width&lt;br /&gt;&lt;br /&gt;[Bindable(false), Category("Appearance"), DefaultValue(null),&lt;br /&gt;Description("The width of the button text in between the decorations for Text mode buttons. The full width of the button for Button mode buttons. Not used for Image mode buttons.")]&lt;br /&gt;&lt;br /&gt;public Unit TellafriendWidth&lt;br /&gt;{&lt;br /&gt;get&lt;br /&gt;{&lt;br /&gt;Unit retWidth = System.Web.UI.WebControls.Unit.Percentage(50);&lt;br /&gt;&lt;br /&gt;switch (TellaFreindText)&lt;br /&gt;{&lt;br /&gt;case TellaFreindText.Your_Name:&lt;br /&gt;retWidth = txt_yourname.Width;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case TellaFreindText.Your_Email:&lt;br /&gt;retWidth = txt_yourEmail.Width;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case TellaFreindText.Friend_Email:&lt;br /&gt;retWidth = txt_friendEmail.Width;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case TellaFreindText.Message:&lt;br /&gt;retWidth = txt_message.Width;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Button:&lt;br /&gt;retWidth = btn_send.Width;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Title:&lt;br /&gt;retWidth = lbl_title.Width;&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;return (retWidth);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;set&lt;br /&gt;{&lt;br /&gt;this.EnsureChildControls();&lt;br /&gt;switch (TellaFreindText)&lt;br /&gt;{&lt;br /&gt;case TellaFreindText.Your_Name:&lt;br /&gt;txt_yourname.Width = value;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Your_Email:&lt;br /&gt;txt_yourEmail.Width = value;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Friend_Email:&lt;br /&gt;txt_friendEmail.Width = value;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Message:&lt;br /&gt;txt_message.Width = value;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Title:&lt;br /&gt;lbl_title.Width = value;&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;#endregion&lt;br /&gt;&lt;br /&gt;#region Tell a Freind Height&lt;br /&gt;&lt;br /&gt;[Bindable(false), Category("Appearance"), DefaultValue(null),&lt;br /&gt;Description("The width of the button text in between the decorations for Text mode buttons. The full width of the button for Button mode buttons. Not used for Image mode buttons.")]&lt;br /&gt;&lt;br /&gt;public Unit TellafriendHeight&lt;br /&gt;{&lt;br /&gt;get&lt;br /&gt;{&lt;br /&gt;Unit retHeight = System.Web.UI.WebControls.Unit.Percentage(50);&lt;br /&gt;&lt;br /&gt;switch (TellaFreindText)&lt;br /&gt;{&lt;br /&gt;case TellaFreindText.Your_Name:&lt;br /&gt;retHeight = txt_yourname.Height;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case TellaFreindText.Your_Email:&lt;br /&gt;retHeight = txt_yourEmail.Height;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case TellaFreindText.Friend_Email:&lt;br /&gt;retHeight = txt_friendEmail.Height;&lt;br /&gt;break;&lt;br /&gt;&lt;br /&gt;case TellaFreindText.Message:&lt;br /&gt;retHeight = txt_message.Height;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Button:&lt;br /&gt;retHeight = btn_send.Height;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Title:&lt;br /&gt;retHeight = lbl_title.Height;&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;return (retHeight);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;set&lt;br /&gt;{&lt;br /&gt;this.EnsureChildControls();&lt;br /&gt;switch (TellaFreindText)&lt;br /&gt;{&lt;br /&gt;case TellaFreindText.Your_Name:&lt;br /&gt;txt_yourname.Height = value;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Your_Email:&lt;br /&gt;txt_yourEmail.Height = value;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Friend_Email:&lt;br /&gt;txt_friendEmail.Height = value;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Message:&lt;br /&gt;txt_message.Height = value;&lt;br /&gt;break;&lt;br /&gt;case TellaFreindText.Title:&lt;br /&gt;lbl_title.Height = value;&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;#endregion&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Create Tell a Friend object control property.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#region Tell a FriendText&lt;br /&gt;&lt;br /&gt;[Bindable(false), Category("Appearance"),&lt;br /&gt;Description("")]&lt;br /&gt;&lt;br /&gt;public TellaFreindText TellaFreindText&lt;br /&gt;{&lt;br /&gt;get&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;this.EnsureChildControls();&lt;br /&gt;&lt;br /&gt;TellaFreindText retVal;&lt;br /&gt;&lt;br /&gt;if (ViewState["textid"] == null)&lt;br /&gt;retVal = TellaFreindText.Your_Name;&lt;br /&gt;else&lt;br /&gt;retVal = (TellaFreindText)ViewState["textid"];&lt;br /&gt;&lt;br /&gt;return (retVal);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;set&lt;br /&gt;{&lt;br /&gt;ViewState["textid"] = value;&lt;br /&gt;this.EnsureChildControls();&lt;br /&gt;TellaFreindText retVal;&lt;br /&gt;retVal = value;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;#endregion&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Bind Tell a Friend control&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#region Bind&lt;br /&gt;&lt;br /&gt;protected override void CreateChildControls()&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;req1 = new RequiredFieldValidator();&lt;br /&gt;req2 = new RequiredFieldValidator();&lt;br /&gt;req3 = new RequiredFieldValidator();&lt;br /&gt;req4 = new RequiredFieldValidator();&lt;br /&gt;&lt;br /&gt;reg1 = new RegularExpressionValidator();&lt;br /&gt;reg2 = new RegularExpressionValidator();&lt;br /&gt;&lt;br /&gt;vs = new ValidationSummary();&lt;br /&gt;&lt;br /&gt;lbl_title = new Label();&lt;br /&gt;&lt;br /&gt;txt_yourname = new TextBox();&lt;br /&gt;txt_yourEmail = new TextBox();&lt;br /&gt;txt_friendEmail = new TextBox();&lt;br /&gt;txt_message = new TextBox();&lt;br /&gt;&lt;br /&gt;btn_send = new Button();&lt;br /&gt;btn_send.Click+=new EventHandler(btn_send_Click);&lt;br /&gt;&lt;br /&gt;HtmlTable table = new HtmlTable();&lt;br /&gt;HtmlTableRow newRow;&lt;br /&gt;HtmlTableCell newCell;&lt;br /&gt;&lt;br /&gt;table.Border = 0;&lt;br /&gt;table.Style.Add("DISPLAY", "inline");&lt;br /&gt;table.Style.Add("VERTICAL-ALIGN", "middle");&lt;br /&gt;&lt;br /&gt;///1st row&lt;br /&gt;newRow = new HtmlTableRow();&lt;br /&gt;newCell = new HtmlTableCell();&lt;br /&gt;&lt;br /&gt;newCell.Controls.Add(lbl_title);&lt;br /&gt;newCell.ColSpan = 2;&lt;br /&gt;newRow.Cells.Add(newCell);&lt;br /&gt;table.Rows.Add(newRow);&lt;br /&gt;&lt;br /&gt;///2nd row&lt;br /&gt;newRow =new HtmlTableRow();&lt;br /&gt;newCell = new HtmlTableCell();&lt;br /&gt;newCell.Align = "right";&lt;br /&gt;newCell.InnerHtml = "Your Name:";&lt;br /&gt;newRow.Controls.Add(newCell);&lt;br /&gt;&lt;br /&gt;newCell = new HtmlTableCell();&lt;br /&gt;txt_yourname.ID = "txtyourName";&lt;br /&gt;newCell.Controls.Add(txt_yourname);&lt;br /&gt;&lt;br /&gt;req1.ControlToValidate = txt_yourname.ID;&lt;br /&gt;req1.ErrorMessage = "Enter Your Name";&lt;br /&gt;req1.SetFocusOnError = true;&lt;br /&gt;req1.Display = ValidatorDisplay.None;&lt;br /&gt;&lt;br /&gt;newCell.Controls.Add(req1);&lt;br /&gt;&lt;br /&gt;newRow.Cells.Add(newCell);&lt;br /&gt;table.Rows.Add(newRow);&lt;br /&gt;&lt;br /&gt;//3dr row&lt;br /&gt;newRow = new HtmlTableRow();&lt;br /&gt;newCell = new HtmlTableCell();&lt;br /&gt;newCell.Align = "right";&lt;br /&gt;newCell.InnerHtml = "Your Email:";&lt;br /&gt;newRow.Controls.Add(newCell);&lt;br /&gt;&lt;br /&gt;newCell = new HtmlTableCell();&lt;br /&gt;txt_yourEmail.ID = "txtyourEmail";&lt;br /&gt;newCell.Controls.Add(txt_yourEmail);&lt;br /&gt;&lt;br /&gt;req2.ControlToValidate = txt_yourEmail.ID;&lt;br /&gt;req2.ErrorMessage = "Enter Your Email Address";&lt;br /&gt;req2.SetFocusOnError = true;&lt;br /&gt;req2.Display = ValidatorDisplay.None;&lt;br /&gt;newCell.Controls.Add(req2);&lt;br /&gt;&lt;br /&gt;reg1.ControlToValidate = txt_yourEmail.ID;&lt;br /&gt;reg1.ErrorMessage = "Invalid Email Address";&lt;br /&gt;reg1.ValidationExpression = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";&lt;br /&gt;reg1.SetFocusOnError = true;&lt;br /&gt;reg1.Display = ValidatorDisplay.None;&lt;br /&gt;newCell.Controls.Add(reg1);&lt;br /&gt;&lt;br /&gt;newRow.Cells.Add(newCell);&lt;br /&gt;table.Rows.Add(newRow);&lt;br /&gt;&lt;br /&gt;//4th row&lt;br /&gt;newRow = new HtmlTableRow();&lt;br /&gt;newCell = new HtmlTableCell();&lt;br /&gt;newCell.Align = "right";&lt;br /&gt;newCell.InnerHtml = "Friend's Email:";&lt;br /&gt;newRow.Controls.Add(newCell);&lt;br /&gt;&lt;br /&gt;newCell = new HtmlTableCell();&lt;br /&gt;txt_friendEmail.ID = "txtFriendEmail";&lt;br /&gt;newCell.Controls.Add(txt_friendEmail);&lt;br /&gt;&lt;br /&gt;req3.ControlToValidate = txt_friendEmail.ID;&lt;br /&gt;req3.ErrorMessage = "Enter Your Freind's Email Address";&lt;br /&gt;req3.SetFocusOnError = true;&lt;br /&gt;req3.Display = ValidatorDisplay.None;&lt;br /&gt;newCell.Controls.Add(req3);&lt;br /&gt;&lt;br /&gt;reg2.ControlToValidate = txt_friendEmail.ID;&lt;br /&gt;reg2.ErrorMessage = "Invalid Email Address";&lt;br /&gt;reg2.ValidationExpression = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";&lt;br /&gt;reg2.SetFocusOnError = true;&lt;br /&gt;reg2.Display = ValidatorDisplay.None;&lt;br /&gt;newCell.Controls.Add(reg2);&lt;br /&gt;&lt;br /&gt;newRow.Cells.Add(newCell);&lt;br /&gt;table.Rows.Add(newRow);&lt;br /&gt;&lt;br /&gt;//5th row&lt;br /&gt;newRow = new HtmlTableRow();&lt;br /&gt;newCell = new HtmlTableCell();&lt;br /&gt;newCell.Align = "right";&lt;br /&gt;newCell.InnerHtml = "Message:";&lt;br /&gt;newRow.Controls.Add(newCell);&lt;br /&gt;&lt;br /&gt;newCell = new HtmlTableCell();&lt;br /&gt;txt_message.TextMode = TextBoxMode.MultiLine;&lt;br /&gt;txt_message.ID = "txtMessage";&lt;br /&gt;newCell.Controls.Add(txt_message);&lt;br /&gt;&lt;br /&gt;req4.ControlToValidate = txt_message.ID;&lt;br /&gt;req4.ErrorMessage = "Enter Message";&lt;br /&gt;req4.SetFocusOnError = true;&lt;br /&gt;req4.Display = ValidatorDisplay.None;&lt;br /&gt;newCell.Controls.Add(req4);&lt;br /&gt;&lt;br /&gt;newRow.Cells.Add(newCell);&lt;br /&gt;table.Rows.Add(newRow);&lt;br /&gt;&lt;br /&gt;//6th row&lt;br /&gt;newRow = new HtmlTableRow();&lt;br /&gt;newCell = new HtmlTableCell();&lt;br /&gt;newCell.Align = "right";&lt;br /&gt;newCell.InnerHtml = "";&lt;br /&gt;newRow.Controls.Add(newCell);&lt;br /&gt;&lt;br /&gt;newCell = new HtmlTableCell();&lt;br /&gt;&lt;br /&gt;newCell.Controls.Add(btn_send);&lt;br /&gt;&lt;br /&gt;vs.ShowMessageBox = true;&lt;br /&gt;vs.ShowSummary = false;&lt;br /&gt;newCell.Controls.Add(vs);&lt;br /&gt;&lt;br /&gt;newRow.Cells.Add(newCell);&lt;br /&gt;table.Rows.Add(newRow);&lt;br /&gt;&lt;br /&gt;table.CellPadding = 2;&lt;br /&gt;table.CellSpacing = 4;&lt;br /&gt;Controls.Add(table);&lt;br /&gt;&lt;br /&gt;this.TellaFreindText = TellaFreindText.Button;&lt;br /&gt;this.Text = "Send Message";&lt;br /&gt;//this.Text = "Enter your name";&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;#endregion&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Rise Button event and send mail &lt;br /&gt;&lt;code&gt;&lt;br /&gt;#region Button Event&lt;br /&gt;&lt;br /&gt;///&lt;br /&gt;/// This delegate is called when the CoolButtonMode is set to Text.&lt;br /&gt;/// It's only job is to forward the event to any registered handelers that&lt;br /&gt;/// are encapsulating this control, including parent composite controls, or&lt;br /&gt;/// the page itself.&lt;br /&gt;///&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public void btn_send_Click(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();&lt;br /&gt;TellaFreindText = TellaFreindText.Your_Name;&lt;br /&gt;string subject = "Mail from" + this.Text;&lt;br /&gt;TellaFreindText = TellaFreindText.Your_Email;&lt;br /&gt;string from = this.Text;&lt;br /&gt;TellaFreindText = TellaFreindText.Friend_Email;&lt;br /&gt;string to = this.Text;&lt;br /&gt;TellaFreindText = TellaFreindText.Message;&lt;br /&gt;string body = this.Text;&lt;br /&gt;&lt;br /&gt;System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage(from, to, subject, body);&lt;br /&gt;System.Net.Mail.SmtpClient cl = new System.Net.Mail.SmtpClient("localhost");&lt;br /&gt;mm.IsBodyHtml = true;&lt;br /&gt;cl.Send(mm);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;#endregion&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Ending tag of class and namespace&lt;br /&gt;&lt;code&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Create other namespace for design control&lt;br /&gt;&lt;code&gt;&lt;br /&gt;namespace ccc.TellaFriend.Design&lt;br /&gt;{&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Create Class with ControlDesigner implementation to design control at design time&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public class TellaFriendDesing :ControlDesigner&lt;br /&gt;{&lt;br /&gt;///&lt;br /&gt;/// Returns a design view of the control as rendered by the control itself.&lt;br /&gt;///&lt;br /&gt;/// The HTML of the design time control.&lt;br /&gt;///&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;region Bind control at desing time&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#region Bind control at desing time&lt;br /&gt;&lt;br /&gt;public override string GetDesignTimeHtml()&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;TellaFriend tf = (TellaFriend)Component;&lt;br /&gt;&lt;br /&gt;// If there are no controls, then it's the first time through the&lt;br /&gt;// designer, so set the text to the unique id. This will also&lt;br /&gt;// cause EnsureChildControls() to be called in Text(), which will&lt;br /&gt;// build out the rest of the control.&lt;br /&gt;if (tf.Controls.Count == 0)&lt;br /&gt;tf.Text = tf.UniqueID;&lt;br /&gt;&lt;br /&gt;StringWriter sw = new StringWriter();&lt;br /&gt;HtmlTextWriter tw = new HtmlTextWriter(sw);&lt;br /&gt;&lt;br /&gt;tf.RenderBeginTag(tw);&lt;br /&gt;tf.RenderControl(tw);&lt;br /&gt;tf.RenderEndTag(tw);&lt;br /&gt;&lt;br /&gt;return (sw.ToString());&lt;br /&gt;}&lt;br /&gt;#endregion&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Ending tag of class and namespace&lt;br /&gt;&lt;code&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-1447723368216257339?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/1447723368216257339/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=1447723368216257339' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/1447723368216257339'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/1447723368216257339'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/12/building-custom-control-tell-friend.html' title='Building Custom Control : Tell A Friend Custom Control'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-8037340225721080078</id><published>2008-12-12T05:21:00.001-08:00</published><updated>2008-12-12T05:46:07.743-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Graphics GDI+'/><title type='text'>Watermark on image : Draw string on the image</title><content type='html'>Page Load event&lt;br /&gt;&lt;code&gt;&lt;br /&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (!IsPostBack)&lt;br /&gt;        {&lt;br /&gt;            AddWatermark("Demo version");&lt;br /&gt;     // Add watermark with "Demo version" text&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Method to add WaterMark text on the image&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    public void AddWatermark(string watermarkText)&lt;br /&gt;    {&lt;br /&gt; // get image from specific path&lt;br /&gt;        System.Drawing.Image bitmap = (System.Drawing.Image)Bitmap.FromFile(Server.MapPath("1.jpg"));&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;        Font font = new Font("Arial", 20, FontStyle.Bold, GraphicsUnit.Pixel);&lt;br /&gt;        &lt;br /&gt; Color color = Color.FromArgb(255, 255, 0, 0); &lt;br /&gt; //Adds a red watermark with.&lt;br /&gt;        &lt;br /&gt; Point atPoint = new Point(bitmap.Width/2, bitmap.Height/2); &lt;br /&gt; //The pixel point to draw the watermark at (this example puts it at center point (x, y)).&lt;br /&gt;        &lt;br /&gt; SolidBrush brush = new SolidBrush(color);&lt;br /&gt;&lt;br /&gt;        Graphics graphics = Graphics.FromImage(bitmap);&lt;br /&gt;       &lt;br /&gt;        StringFormat sf=new StringFormat();&lt;br /&gt;        sf.Alignment= StringAlignment.Center;&lt;br /&gt;        sf.LineAlignment= StringAlignment.Center;&lt;br /&gt;        // String Format to draw string at center point&lt;br /&gt; &lt;br /&gt; graphics.DrawString(watermarkText, font, brush, atPoint,sf);&lt;br /&gt; // Draw string on image&lt;br /&gt;&lt;br /&gt;        graphics.Dispose();&lt;br /&gt;        MemoryStream m = new MemoryStream();&lt;br /&gt;        bitmap.Save(m,System.Drawing.Imaging.ImageFormat.Jpeg);&lt;br /&gt;        m.WriteTo(Response.OutputStream);&lt;br /&gt;        m.Dispose();&lt;br /&gt;        base.Dispose();&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-8037340225721080078?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/8037340225721080078/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=8037340225721080078' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/8037340225721080078'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/8037340225721080078'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/12/page-load-event-protected-void.html' title='Watermark on image : Draw string on the image'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-1555678842406795536</id><published>2008-12-12T03:25:00.000-08:00</published><updated>2008-12-12T05:46:52.266-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Other'/><title type='text'>Remember me on this computer - Store username and password in cookie and login automatically.</title><content type='html'>Write below code on page load event to check cookie it exist or not.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;{&lt;br /&gt;if (!IsPostBack)&lt;br /&gt;{&lt;br /&gt; // check your cookies is null or not&lt;br /&gt; if (Request.Cookies["myCockie"] != null) //Cookie Exists??&lt;br /&gt; {&lt;br /&gt;&lt;br /&gt;  // Create cookie object&lt;br /&gt;  HttpCookie cookie = Request.Cookies.Get("myCockie");&lt;br /&gt;                &lt;br /&gt;  // retrive username and password from cookie&lt;br /&gt;  string user = cookie.Values["Username"].ToString();&lt;br /&gt;                string pass = cookie.Values["Password"].ToString();&lt;br /&gt;                &lt;br /&gt;  if (user != "")&lt;br /&gt;                {&lt;br /&gt;                    txtUname.Text = user; &lt;br /&gt;      //Write the username onto login username textbox &lt;br /&gt;                }&lt;br /&gt;                if (pass != "")&lt;br /&gt;  {&lt;br /&gt;                    txtPW.Attributes.Add("value", pass);&lt;br /&gt;      // set password string to the password textbox.&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  // check "remember me on this computer" checkbox&lt;br /&gt;                chkRemmember.Checked = true;&lt;br /&gt;  &lt;br /&gt;  // call method to login into the system&lt;br /&gt;  Login_User(txtUname.Text, txtPW.Text);&lt;br /&gt; }&lt;br /&gt;        txtUname.Focus();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;On Login Button Click Event, Store username and password in cookie.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;protected void btnLogin_Click(object sender, ImageClickEventArgs e)&lt;br /&gt;{&lt;br /&gt; if (chkRemmember.Checked)&lt;br /&gt;        {&lt;br /&gt;  HttpCookie myCookie = new HttpCookie("myCockie"); &lt;br /&gt;  //Instance the new cookie&lt;br /&gt;         &lt;br /&gt;         Response.Cookies.Remove("myCockie"); &lt;br /&gt;  //Remove previous cookie&lt;br /&gt;&lt;br /&gt;  Response.Cookies.Add(myCookie);&lt;br /&gt;&lt;br /&gt;  myCookie.Values.Add("Username", this.txtUname.Text); &lt;br /&gt;  //Add the username field to the cookie&lt;br /&gt;&lt;br /&gt;         DateTime deathDate = DateTime.Now.AddYears(1); &lt;br /&gt;  //Days of life&lt;br /&gt;&lt;br /&gt;  Response.Cookies["myCockie"].Expires = deathDate; &lt;br /&gt;  //Assign the life period&lt;br /&gt;            &lt;br /&gt;  //IF YOU WANT SAVE THE PASSWORD TOO (IT IS NOT RECOMMENDED)&lt;br /&gt;&lt;br /&gt;          myCookie.Values.Add("Password", this.txtPW.Text);&lt;br /&gt; }&lt;br /&gt; // call method to login into the system&lt;br /&gt; Login_User(txtUname.Text, txtPW.Text);&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Method to login into the system&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public void Login_User(string username,string password)&lt;br /&gt;    {&lt;br /&gt;       // Login user into the system &lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-1555678842406795536?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/1555678842406795536/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=1555678842406795536' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/1555678842406795536'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/1555678842406795536'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/12/remember-me-on-this-computer-store.html' title='Remember me on this computer - Store username and password in cookie and login automatically.'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-5934979458139135350</id><published>2008-12-12T03:20:00.000-08:00</published><updated>2008-12-12T05:46:52.266-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Other'/><title type='text'>Building URL with www.</title><content type='html'>&lt;code&gt;&lt;br /&gt;// Collect url information being requested&lt;br /&gt;  string urlHttps = Request.ServerVariables["HTTPS"];&lt;br /&gt;&lt;br /&gt;  string urlHost = Request.ServerVariables["HTTP_HOST"];&lt;br /&gt;  string urlUrl = Request.ServerVariables["URL"];&lt;br /&gt;  string urlQueryString = Request.ServerVariables["QUERY_STRING"];&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  // Check if www appears in the domain and begin building url to redirect to if it doesn’t&lt;br /&gt;  if (!urlHost.Contains("www."))&lt;br /&gt;  {&lt;br /&gt;         string urlNewUrl = "http://www.";&lt;br /&gt;        //Add the domain, folder(s) and page requested as well as remove directory indexes&lt;br /&gt;        urlNewUrl = urlNewUrl + urlHost + urlUrl;&lt;br /&gt;        //If there is a querystring, add it to the redirect link&lt;br /&gt;        if (urlQueryString.Length &gt; 0)&lt;br /&gt;        urlNewUrl = urlNewUrl + "?" + urlQueryString;&lt;br /&gt;        //Do the actual 301 redirect to the newly constructed url&lt;br /&gt;        Response.Status = "301 Moved Permanently";&lt;br /&gt;        Response.AddHeader("Location", urlNewUrl);&lt;br /&gt;        Response.End();&lt;br /&gt;   }&lt;br /&gt; &lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-5934979458139135350?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/5934979458139135350/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=5934979458139135350' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/5934979458139135350'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/5934979458139135350'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/12/building-url-with-www.html' title='Building URL with www.'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-8711546698407438140</id><published>2008-12-04T03:25:00.000-08:00</published><updated>2008-12-12T05:45:55.102-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Graphics GDI+'/><title type='text'>HIGHLIGHT STRING IN IMAGE [ DRAW STRING WITH HIGHLIGHT WORD ]</title><content type='html'>Bitmap b = new Bitmap(700, 100);&lt;br /&gt;            Graphics g = Graphics.FromImage((System.Drawing.Image)b);&lt;br /&gt;            &lt;br /&gt;            string myString = "This is a string.My highlight word : search highlighted word.";&lt;br /&gt;&lt;br /&gt;            // Declare the word to highlight.&lt;br /&gt;            string searchWord = "search highlighted word";&lt;br /&gt;&lt;br /&gt;            // Create a CharacterRange array with the searchWord &lt;br /&gt;            // location and length.&lt;br /&gt;            CharacterRange[] CharRanges =&lt;br /&gt;                new CharacterRange[]{new CharacterRange&lt;br /&gt;           (myString.IndexOf(searchWord), searchWord.Length)};&lt;br /&gt;&lt;br /&gt;            // Construct a StringFormat object.&lt;br /&gt;            StringFormat stringFormat = new StringFormat();&lt;br /&gt;&lt;br /&gt;            // Set the ranges on the StringFormat object.&lt;br /&gt;            stringFormat.SetMeasurableCharacterRanges(CharRanges);&lt;br /&gt;&lt;br /&gt;            // Declare the font to write the message in.&lt;br /&gt;            Font MyFont = new Font(FontFamily.GenericSansSerif, 20.0F,&lt;br /&gt;                GraphicsUnit.Pixel);&lt;br /&gt;&lt;br /&gt;            // Construct a new Rectangle.&lt;br /&gt;            Rectangle MyRectangle = new Rectangle(10, 10, 700, 100);&lt;br /&gt;&lt;br /&gt;            // Convert the Rectangle to a RectangleF.&lt;br /&gt;            RectangleF MyRectangleF = (RectangleF)MyRectangle;&lt;br /&gt;&lt;br /&gt;            // Get the Region to highlight by calling the &lt;br /&gt;            // MeasureCharacterRanges method.&lt;br /&gt;            Region[] charRegion = g.MeasureCharacterRanges(myString,&lt;br /&gt;                MyFont, MyRectangleF, stringFormat);&lt;br /&gt;&lt;br /&gt;            // Draw the message string on the form.&lt;br /&gt;            g.DrawString(myString, MyFont, Brushes.Red,&lt;br /&gt;                MyRectangleF);&lt;br /&gt;&lt;br /&gt;            // Fill in the region using a semi-transparent color.&lt;br /&gt;            g.FillRegion(new SolidBrush(Color.FromArgb(50, Color.Black)),&lt;br /&gt;                charRegion[0]);&lt;br /&gt;            &lt;br /&gt;            // save image to the root &lt;br /&gt;            b.Save(Server.MapPath("MyImage.png"), System.Drawing.Imaging.ImageFormat.Png);&lt;br /&gt;            &lt;br /&gt;            // write image on the page&lt;br /&gt;            //MemoryStream m = new MemoryStream();&lt;br /&gt;            //b.Save(m, System.Drawing.Imaging.ImageFormat.Png);&lt;br /&gt;            //m.WriteTo(Response.OutputStream);&lt;br /&gt;            b.Dispose();&lt;br /&gt;            MyFont.Dispose();&lt;br /&gt;            g.Dispose();&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-8711546698407438140?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/8711546698407438140/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=8711546698407438140' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/8711546698407438140'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/8711546698407438140'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/12/highlight-string-in-image-draw-string.html' title='HIGHLIGHT STRING IN IMAGE [ DRAW STRING WITH HIGHLIGHT WORD ]'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-2498826332654607871</id><published>2008-12-01T05:05:00.000-08:00</published><updated>2008-12-01T05:10:17.108-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='SQL SERVER'/><title type='text'>LOOPING IN STORED PROCEDURE [CURSOR IN SQL SERVER]</title><content type='html'>-- DECLARE VARIABLE AS INT&lt;br /&gt; DECLARE @PRODUCTID AS INT &lt;br /&gt;&lt;br /&gt; DECLARE SQLCURSOR CURSOR FOR&lt;br /&gt; SELECT PRODUCTID FROM TBLPRODUCTMASTER&lt;br /&gt; -- DECLARE CURSOR FOR SELECTED PRODUCTID&lt;br /&gt; -- I HAVE ONE TABLE NAMED TBLPRODUCTMASTER AND I AM GETTING ALL PRODUCTID    FROM THIS TABLE AND PRINT INDIVIDUAL PRODUCTID&lt;br /&gt; OPEN SQLCURSOR&lt;br /&gt; FETCH NEXT FROM SQLCURSOR INTO @PRODUCTID&lt;br /&gt; WHILE(@@FETCH_STATUS=0)&lt;br /&gt; BEGIN&lt;br /&gt;  PRINT @PRODUCTID&lt;br /&gt;  -- YOU CAN USE EACH PRODUCTID AND MAKE AN OPERATION ON THIS ID&lt;br /&gt;  FETCH NEXT FROM SQLCURSOR INTO @PRODUCTID&lt;br /&gt; END&lt;br /&gt; CLOSE SQLCURSOR&lt;br /&gt; DEALLOCATE SQLCURSOR&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-2498826332654607871?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/2498826332654607871/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=2498826332654607871' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/2498826332654607871'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/2498826332654607871'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/12/looping-in-stored-procedure-cursor-in.html' title='LOOPING IN STORED PROCEDURE [CURSOR IN SQL SERVER]'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-6475625471055947192</id><published>2008-12-01T03:56:00.000-08:00</published><updated>2008-12-01T21:47:21.792-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Graphics GDI+'/><title type='text'>CHANGE IMAGE COLOR USING C#  ( GRAPHICS GDI+ )</title><content type='html'>using System.Drawing;&lt;br /&gt;using System.Drawing.Imaging;&lt;br /&gt;using System.Drawing.Text;&lt;br /&gt;using System.Runtime.InteropServices;&lt;br /&gt;using System.Drawing.Drawing2D;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (!IsPostBack)&lt;br /&gt;        {&lt;br /&gt;            Color NewCol = Color.Green; // REPLACED COLOR&lt;br /&gt;            Bitmap b = new Bitmap(Server.MapPath("clipart.png"));&lt;br /&gt;            b = ChangeImageColor((System.Drawing.Image)b, NewCol);&lt;br /&gt;            b.Save(Server.MapPath("NewImage.png"), ImageFormat.Png);&lt;br /&gt;            b.Dispose();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    private Bitmap ChangeImageColor(System.Drawing.Image source, Color nCol)&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;        // Create a bitmap from the image&lt;br /&gt;&lt;br /&gt;        Bitmap bmp = new Bitmap(source);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        // Loop through each pixel in the bitmap. If we find&lt;br /&gt;&lt;br /&gt;        // a transparent pixel, we leave it alone.&lt;br /&gt;&lt;br /&gt;        for (int y = 0; y &lt; bmp.Height; y++)&lt;br /&gt;        {&lt;br /&gt;&lt;br /&gt;            for (int x = 0; x &lt; bmp.Width; x++)&lt;br /&gt;            {&lt;br /&gt;&lt;br /&gt;                // Get the color of the current pixel&lt;br /&gt;&lt;br /&gt;                Color col = bmp.GetPixel(x, y);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;                if (col.A != 0) //non alpha or any matched color&lt;br /&gt;                {&lt;br /&gt;&lt;br /&gt;                    int r = (int)(nCol.R);&lt;br /&gt;&lt;br /&gt;                    int g = (int)(nCol.G);&lt;br /&gt;&lt;br /&gt;                    int b = (int)(nCol.B);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;                    // To make the image brighter, increase this number&lt;br /&gt;&lt;br /&gt;                    int light = 0;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;                    // Create the new gray color&lt;br /&gt;&lt;br /&gt;                    Color newColor = Color.FromArgb(&lt;br /&gt;                    (r + light &gt; 255 ? r : r + light),&lt;br /&gt;&lt;br /&gt;                    (g + light &gt; 255 ? g : g + light),&lt;br /&gt;&lt;br /&gt;                    (b + light &gt; 255 ? b : b + light));&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;                    bmp.SetPixel(x, y, newColor);&lt;br /&gt;&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        return bmp;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;NOTE: Image color must be in single and image file must be transparent image.&lt;br /&gt;This code helps you for clipart image to replace one color to other color.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Look at these images.&lt;br /&gt;&lt;br /&gt;Old Image :&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_ParaizjbYyQ/STPRfmmP3KI/AAAAAAAAAR8/hyLyFtBNS2I/s1600-h/clipart.png"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 200px; height: 73px;" src="http://3.bp.blogspot.com/_ParaizjbYyQ/STPRfmmP3KI/AAAAAAAAAR8/hyLyFtBNS2I/s200/clipart.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5274789929448103074" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;New Image :&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_ParaizjbYyQ/STPRp1r_rFI/AAAAAAAAASE/tcTQWqaeoUE/s1600-h/NewImage.png"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 200px; height: 73px;" src="http://4.bp.blogspot.com/_ParaizjbYyQ/STPRp1r_rFI/AAAAAAAAASE/tcTQWqaeoUE/s200/NewImage.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5274790105297431634" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-6475625471055947192?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/6475625471055947192/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=6475625471055947192' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/6475625471055947192'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/6475625471055947192'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/12/change-image-color.html' title='CHANGE IMAGE COLOR USING C#  ( GRAPHICS GDI+ )'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_ParaizjbYyQ/STPRfmmP3KI/AAAAAAAAAR8/hyLyFtBNS2I/s72-c/clipart.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-2339793253888396214</id><published>2008-12-01T02:55:00.000-08:00</published><updated>2008-12-01T03:08:37.708-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Graphics GDI+'/><title type='text'>DRAW STRING WITH MULTI LINES IN FIX RECTANGLE</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_ParaizjbYyQ/STPEA5vH3KI/AAAAAAAAAR0/65785wUp6Lk/s1600-h/TextWithMultilines.png"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 100px; height: 100px;" src="http://4.bp.blogspot.com/_ParaizjbYyQ/STPEA5vH3KI/AAAAAAAAAR0/65785wUp6Lk/s200/TextWithMultilines.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5274775108358495394" /&gt;&lt;/a&gt;&lt;br /&gt;using System.Drawing;&lt;br /&gt;using System.Drawing.Imaging;&lt;br /&gt;using System.Drawing.Text;&lt;br /&gt;using System.Runtime.InteropServices;&lt;br /&gt;using System.Drawing.Drawing2D;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (!IsPostBack)&lt;br /&gt;        {&lt;br /&gt;            Color fontColor = Color.Yellow; // SET FONT COLOR&lt;br /&gt;            Color bg_Color = Color.Blue; // SET BACKGROUNG COLOR&lt;br /&gt;            bool fontBold = false;&lt;br /&gt;            bool fontItalic = false;&lt;br /&gt;            bool fontUnderline = false;&lt;br /&gt;            string[] strArray = new string[4];&lt;br /&gt;            strArray[0] = "My";&lt;br /&gt;            strArray[1] = "Name";&lt;br /&gt;            strArray[2] = "is";&lt;br /&gt;            strArray[3] = "Khan";&lt;br /&gt;&lt;br /&gt;            string fontFamily = "impact"; // FONT FAMILY&lt;br /&gt;            int w = 600; // IMAGE WIDTH&lt;br /&gt;            int h = 600; // IMAGE HEIGHT&lt;br /&gt;            int noOfLines = strArray.Length;&lt;br /&gt;&lt;br /&gt;            SolidBrush color;&lt;br /&gt;            FontStyle fontStyle = FontStyle.Regular;&lt;br /&gt;            if (fontBold) fontStyle |= FontStyle.Bold;&lt;br /&gt;            if (fontItalic) fontStyle |= FontStyle.Italic;&lt;br /&gt;            if (fontUnderline) fontStyle |= FontStyle.Underline;&lt;br /&gt;&lt;br /&gt;            Rectangle target = new Rectangle(0, 0, w, h); // GET TARGET RECTANGLE&lt;br /&gt;            Bitmap bitmap = new Bitmap(w, h);&lt;br /&gt;            Graphics g = Graphics.FromImage(bitmap);&lt;br /&gt;            color = new SolidBrush(bg_Color);&lt;br /&gt;            g.FillRectangle(color, target); // FILL BACKGROUND&lt;br /&gt;            g.SmoothingMode = SmoothingMode.AntiAlias;&lt;br /&gt;            g.InterpolationMode = InterpolationMode.HighQualityBicubic;&lt;br /&gt;            g.PixelOffsetMode = PixelOffsetMode.HighQuality;&lt;br /&gt;&lt;br /&gt;            int trgheight = target.Height / noOfLines;&lt;br /&gt;            int x = 3; // LEAVE SPACE TO LEFT,TOP,RIGHT AND BOTTOM OF IMAGE&lt;br /&gt;            int tLeft = target.Left + x;&lt;br /&gt;            int tTop = target.Top + x;&lt;br /&gt;            int tRight = target.Right - x;&lt;br /&gt;            int tBottom = target.Bottom - x;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            Font the_font = new Font(fontFamily, trgheight, fontStyle, GraphicsUnit.Pixel);&lt;br /&gt;&lt;br /&gt;            StringFormat sf = new StringFormat();&lt;br /&gt;            sf.LineAlignment = StringAlignment.Center;&lt;br /&gt;            sf.Alignment = StringAlignment.Center;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            GraphicsPath text_path = new GraphicsPath();&lt;br /&gt;&lt;br /&gt;            int useHeight = 0;&lt;br /&gt;            for (int count = 0; count &lt; noOfLines; count++)&lt;br /&gt;            {&lt;br /&gt;                text_path.AddString(strArray[count], the_font.FontFamily, (int)fontStyle, trgheight, new PointF(0, useHeight), sf);&lt;br /&gt;                useHeight += trgheight;&lt;br /&gt;            }&lt;br /&gt;            &lt;br /&gt;&lt;br /&gt;            RectangleF text_rectf = text_path.GetBounds();&lt;br /&gt;&lt;br /&gt;            PointF[] target_pts = new PointF[3];&lt;br /&gt;            target_pts[0] = new PointF(tLeft, tTop);&lt;br /&gt;            target_pts[1] = new PointF(tRight, tTop);&lt;br /&gt;            target_pts[2] = new PointF(tLeft, tBottom);&lt;br /&gt;            //GET POINTS TO DRAW TEXT INTO RECTANGLE&lt;br /&gt;&lt;br /&gt;            g.Transform = new Matrix(text_rectf, target_pts);&lt;br /&gt;&lt;br /&gt;            color = new SolidBrush(fontColor);&lt;br /&gt;            g.FillPath(color, text_path);&lt;br /&gt;&lt;br /&gt;            g.ResetTransform();&lt;br /&gt;            text_path.Dispose();&lt;br /&gt;            sf.Dispose();&lt;br /&gt;            the_font.Dispose();&lt;br /&gt;            g.Dispose();&lt;br /&gt;            bitmap.Save(Server.MapPath("TextWithMultilines.png"), System.Drawing.Imaging.ImageFormat.Png); //  SAVE IMAGE TO THE ROOT &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;    }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-2339793253888396214?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/2339793253888396214/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=2339793253888396214' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/2339793253888396214'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/2339793253888396214'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/12/draw-string-with-multi-lines-in-fix.html' title='DRAW STRING WITH MULTI LINES IN FIX RECTANGLE'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_ParaizjbYyQ/STPEA5vH3KI/AAAAAAAAAR0/65785wUp6Lk/s72-c/TextWithMultilines.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-5584972939005856948</id><published>2008-12-01T02:51:00.001-08:00</published><updated>2008-12-01T03:08:37.709-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Graphics GDI+'/><title type='text'>DRAW STRING WITH TWO LINES IN FIX RECTANGLE</title><content type='html'>using System.Drawing;&lt;br /&gt;using System.Drawing.Imaging;&lt;br /&gt;using System.Drawing.Text;&lt;br /&gt;using System.Runtime.InteropServices;&lt;br /&gt;using System.Drawing.Drawing2D;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (!IsPostBack)&lt;br /&gt;        {&lt;br /&gt;            Color fontColor = Color.Red; // SET FONT COLOR&lt;br /&gt;            Color bg_Color = Color.Black; // SET BACKGROUNG COLOR&lt;br /&gt;            bool fontBold = false;&lt;br /&gt;            bool fontItalic = false;&lt;br /&gt;            bool fontUnderline = false;&lt;br /&gt;            string text = "I love"; // TEXT&lt;br /&gt;            string text1 = "India";&lt;br /&gt;&lt;br /&gt;            string fontFamily = "impact"; // FONT FAMILY&lt;br /&gt;            int w = 600; // IMAGE WIDTH&lt;br /&gt;            int h = 400; // IMAGE HEIGHT&lt;br /&gt;            int noOfLines = 2;&lt;br /&gt;&lt;br /&gt;            SolidBrush color;&lt;br /&gt;            FontStyle fontStyle = FontStyle.Regular;&lt;br /&gt;            if (fontBold) fontStyle |= FontStyle.Bold;&lt;br /&gt;            if (fontItalic) fontStyle |= FontStyle.Italic;&lt;br /&gt;            if (fontUnderline) fontStyle |= FontStyle.Underline;&lt;br /&gt;&lt;br /&gt;            Rectangle target = new Rectangle(0, 0, w, h); // GET TARGET RECTANGLE&lt;br /&gt;            Bitmap bitmap = new Bitmap(w, h);&lt;br /&gt;            Graphics g = Graphics.FromImage(bitmap);&lt;br /&gt;            color = new SolidBrush(bg_Color);&lt;br /&gt;            g.FillRectangle(color, target); // FILL BACKGROUND&lt;br /&gt;            g.SmoothingMode = SmoothingMode.AntiAlias;&lt;br /&gt;            g.InterpolationMode = InterpolationMode.HighQualityBicubic;&lt;br /&gt;            g.PixelOffsetMode = PixelOffsetMode.HighQuality;&lt;br /&gt;&lt;br /&gt;            int trgheight = target.Height / noOfLines;&lt;br /&gt;            int x = 3; // LEAVE SPACE TO LEFT,TOP,RIGHT AND BOTTOM OF IMAGE&lt;br /&gt;            int tLeft = target.Left + x;&lt;br /&gt;            int tTop = target.Top + x;&lt;br /&gt;            int tRight = target.Right - x;&lt;br /&gt;            int tBottom = target.Bottom - x;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            Font the_font = new Font(fontFamily, trgheight, fontStyle, GraphicsUnit.Pixel);&lt;br /&gt;&lt;br /&gt;            StringFormat sf = new StringFormat();&lt;br /&gt;            sf.LineAlignment = StringAlignment.Center;&lt;br /&gt;            sf.Alignment = StringAlignment.Center;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            GraphicsPath text_path = new GraphicsPath();&lt;br /&gt;&lt;br /&gt;            int useHeight = 0;&lt;br /&gt;&lt;br /&gt;            text_path.AddString(text, the_font.FontFamily, (int)fontStyle, trgheight, new PointF(0, useHeight), sf);&lt;br /&gt;            useHeight += trgheight;&lt;br /&gt;&lt;br /&gt;            text_path.AddString(text1, the_font.FontFamily, (int)fontStyle, trgheight, new PointF(0, useHeight), sf);&lt;br /&gt;&lt;br /&gt;            RectangleF text_rectf = text_path.GetBounds();&lt;br /&gt;&lt;br /&gt;            PointF[] target_pts = new PointF[3];&lt;br /&gt;            target_pts[0] = new PointF(tLeft, tTop);&lt;br /&gt;            target_pts[1] = new PointF(tRight, tTop);&lt;br /&gt;            target_pts[2] = new PointF(tLeft, tBottom);&lt;br /&gt;            //GET POINTS TO DRAW TEXT INTO RECTANGLE&lt;br /&gt;&lt;br /&gt;            g.Transform = new Matrix(text_rectf, target_pts);&lt;br /&gt;&lt;br /&gt;            color = new SolidBrush(fontColor);&lt;br /&gt;            g.FillPath(color, text_path);&lt;br /&gt;&lt;br /&gt;            g.ResetTransform();&lt;br /&gt;            text_path.Dispose();&lt;br /&gt;            sf.Dispose();&lt;br /&gt;            the_font.Dispose();&lt;br /&gt;            g.Dispose();&lt;br /&gt;            bitmap.Save(Server.MapPath("TextWithTwo.png"), System.Drawing.Imaging.ImageFormat.Png); //  SAVE IMAGE TO THE ROOT &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;    }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-5584972939005856948?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/5584972939005856948/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=5584972939005856948' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/5584972939005856948'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/5584972939005856948'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/12/draw-string-with-two-lines-in-fix.html' title='DRAW STRING WITH TWO LINES IN FIX RECTANGLE'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-8008541791995889229</id><published>2008-12-01T02:49:00.001-08:00</published><updated>2008-12-01T03:08:37.709-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Graphics GDI+'/><title type='text'>DRAW STRING IN FIX RECTANGLE WITH BACKGROUNG COLOR, BORDER AND SHADOW</title><content type='html'>using System.Drawing;&lt;br /&gt;using System.Drawing.Imaging;&lt;br /&gt;using System.Drawing.Text;&lt;br /&gt;using System.Runtime.InteropServices;&lt;br /&gt;using System.Drawing.Drawing2D;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// CREATE ENUM FOR SHADOW STYLE&lt;br /&gt;    enum ShadowStyle&lt;br /&gt;    {&lt;br /&gt;        Top_Left,&lt;br /&gt;        Top_Right,&lt;br /&gt;        Bottom_Left,&lt;br /&gt;        Bottom_Right,&lt;br /&gt;        None&lt;br /&gt;    }&lt;br /&gt;    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (!IsPostBack)&lt;br /&gt;        {&lt;br /&gt;            Color fontColor = Color.Red;&lt;br /&gt;            Color shadowColor = Color.Blue; // SET SHADOW COLOR&lt;br /&gt;            Color borderColor = Color.Yellow;&lt;br /&gt;            Color bg_Color = Color.Black;&lt;br /&gt;&lt;br /&gt;            bool fontBold = false;&lt;br /&gt;            bool fontItalic = false;&lt;br /&gt;            bool fontUnderline = false;&lt;br /&gt;&lt;br /&gt;            string text = "WELCOME";&lt;br /&gt;            string fontFamily = "impact";&lt;br /&gt;            int w = 600;&lt;br /&gt;            int h = 200;&lt;br /&gt;            int borderWidth = 5;&lt;br /&gt;&lt;br /&gt;            ShadowStyle shd = ShadowStyle.Top_Right; // SET SHADOW STYLE&lt;br /&gt;&lt;br /&gt;            SolidBrush color;&lt;br /&gt;            FontStyle fontStyle = FontStyle.Regular;&lt;br /&gt;            if (fontBold) fontStyle |= FontStyle.Bold;&lt;br /&gt;            if (fontItalic) fontStyle |= FontStyle.Italic;&lt;br /&gt;            if (fontUnderline) fontStyle |= FontStyle.Underline;&lt;br /&gt;&lt;br /&gt;            Rectangle target = new Rectangle(0, 0, w, h);&lt;br /&gt;            Bitmap bitmap = new Bitmap(w, h);&lt;br /&gt;            Graphics g = Graphics.FromImage(bitmap);&lt;br /&gt;&lt;br /&gt;            color = new SolidBrush(bg_Color);&lt;br /&gt;            g.FillRectangle(color, target);&lt;br /&gt;            g.SmoothingMode = SmoothingMode.AntiAlias;&lt;br /&gt;            g.InterpolationMode = InterpolationMode.HighQualityBicubic;&lt;br /&gt;            g.PixelOffsetMode = PixelOffsetMode.HighQuality;&lt;br /&gt;&lt;br /&gt;            int trgheight = target.Height;&lt;br /&gt;            int x = 3, y = 3;&lt;br /&gt;            int tLeft = target.Left + x;&lt;br /&gt;            int tTop = target.Top + x;&lt;br /&gt;            int tRight = target.Right - x;&lt;br /&gt;            int tBottom = target.Bottom - x;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            Font the_font = new Font(fontFamily, trgheight, fontStyle, GraphicsUnit.Pixel);&lt;br /&gt;&lt;br /&gt;            StringFormat sf = new StringFormat();&lt;br /&gt;            sf.LineAlignment = StringAlignment.Center;&lt;br /&gt;            sf.Alignment = StringAlignment.Center;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            GraphicsPath text_path = new GraphicsPath();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            /* Shadow Style */&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            if (shd != ShadowStyle.None)&lt;br /&gt;            {&lt;br /&gt;                text_path.AddString(text, the_font.FontFamily, (int)fontStyle, trgheight, new PointF(0, 0), sf);&lt;br /&gt;                RectangleF text_rectf1 = text_path.GetBounds();&lt;br /&gt;                PointF[] target_pts1 = new PointF[3];&lt;br /&gt;                switch (shd)&lt;br /&gt;                {&lt;br /&gt;                    case ShadowStyle.Top_Right:&lt;br /&gt;                        target_pts1[0] = new PointF(tLeft + y, tTop - y);&lt;br /&gt;                        target_pts1[1] = new PointF(tRight + y, tTop - y);&lt;br /&gt;                        target_pts1[2] = new PointF(tLeft + y, tBottom - y);&lt;br /&gt;                        break;&lt;br /&gt;                    case ShadowStyle.Top_Left:&lt;br /&gt;                        target_pts1[0] = new PointF(tLeft - y, tTop - y);&lt;br /&gt;                        target_pts1[1] = new PointF(tRight - y, tTop - y);&lt;br /&gt;                        target_pts1[2] = new PointF(tLeft - y, tBottom - y);&lt;br /&gt;                        break;&lt;br /&gt;                    case ShadowStyle.Bottom_Right:&lt;br /&gt;                        target_pts1[0] = new PointF(tLeft + y, tTop + y);&lt;br /&gt;                        target_pts1[1] = new PointF(tRight + y, tTop + y);&lt;br /&gt;                        target_pts1[2] = new PointF(tLeft + y, tBottom + y);&lt;br /&gt;                        break;&lt;br /&gt;                    case ShadowStyle.Bottom_Left:&lt;br /&gt;                        target_pts1[0] = new PointF(tLeft - y, tTop + y);&lt;br /&gt;                        target_pts1[1] = new PointF(tRight - y, tTop + y);&lt;br /&gt;                        target_pts1[2] = new PointF(tLeft - y, tBottom + y);&lt;br /&gt;                        break;&lt;br /&gt;                    default:&lt;br /&gt;                        target_pts1[0] = new PointF(tLeft, tTop);&lt;br /&gt;                        target_pts1[1] = new PointF(tRight, tTop);&lt;br /&gt;                        target_pts1[2] = new PointF(tLeft, tBottom);&lt;br /&gt;                        break;&lt;br /&gt;                }&lt;br /&gt;                color = new SolidBrush(shadowColor);&lt;br /&gt;                g.Transform = new Matrix(text_rectf1, target_pts1);&lt;br /&gt;                g.FillPath(color, text_path);&lt;br /&gt;                text_path = new GraphicsPath();&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            /* Draw Text */&lt;br /&gt;&lt;br /&gt;            text_path.AddString(text, the_font.FontFamily, (int)fontStyle, trgheight, new PointF(0, 0), sf);&lt;br /&gt;            RectangleF text_rectf = text_path.GetBounds();&lt;br /&gt;&lt;br /&gt;            PointF[] target_pts = new PointF[3];&lt;br /&gt;            switch (shd)&lt;br /&gt;            {&lt;br /&gt;                case ShadowStyle.Top_Right:&lt;br /&gt;                    target_pts[0] = new PointF(tLeft, tTop + y);&lt;br /&gt;                    target_pts[1] = new PointF(tRight - y, tTop + y);&lt;br /&gt;                    target_pts[2] = new PointF(tLeft, tBottom);&lt;br /&gt;                    break;&lt;br /&gt;                case ShadowStyle.Top_Left:&lt;br /&gt;                    target_pts[0] = new PointF(tLeft + y, tTop + y);&lt;br /&gt;                    target_pts[1] = new PointF(tRight + y, tTop + y);&lt;br /&gt;                    target_pts[2] = new PointF(tLeft + y, tBottom);&lt;br /&gt;                    break;&lt;br /&gt;                case ShadowStyle.Bottom_Right:&lt;br /&gt;                    target_pts[0] = new PointF(tLeft, tTop - y);&lt;br /&gt;                    target_pts[1] = new PointF(tRight - y, tTop - y);&lt;br /&gt;                    target_pts[2] = new PointF(tLeft, tBottom);&lt;br /&gt;                    break;&lt;br /&gt;                case ShadowStyle.Bottom_Left:&lt;br /&gt;                    target_pts[0] = new PointF(tLeft + y, tTop - y);&lt;br /&gt;                    target_pts[1] = new PointF(tRight + y, tTop - y);&lt;br /&gt;                    target_pts[2] = new PointF(tLeft + y, tBottom);&lt;br /&gt;                    break;&lt;br /&gt;                default:&lt;br /&gt;                    target_pts[0] = new PointF(tLeft, tTop);&lt;br /&gt;                    target_pts[1] = new PointF(tRight, tTop);&lt;br /&gt;                    target_pts[2] = new PointF(tLeft, tBottom);&lt;br /&gt;                    break;&lt;br /&gt;            }&lt;br /&gt;            g.Transform = new Matrix(text_rectf, target_pts);&lt;br /&gt;&lt;br /&gt;            color = new SolidBrush(fontColor);&lt;br /&gt;            g.FillPath(color, text_path);&lt;br /&gt;&lt;br /&gt;            /* DRAW BORDER */&lt;br /&gt;            color = new SolidBrush(borderColor);&lt;br /&gt;            Pen pen = new Pen(color);&lt;br /&gt;            for (int i = 0; i &lt;= borderWidth; i++)&lt;br /&gt;            {&lt;br /&gt;                for (int j = 0; j &lt;= borderWidth; j++)&lt;br /&gt;                {&lt;br /&gt;                    text_path.AddString(text, the_font.FontFamily, (int)fontStyle, target.Height, new PointF(i, j), sf);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            g.DrawPath(pen, text_path);&lt;br /&gt;            /* END */&lt;br /&gt;&lt;br /&gt;            g.ResetTransform();&lt;br /&gt;            text_path.Dispose();&lt;br /&gt;            sf.Dispose();&lt;br /&gt;            the_font.Dispose();&lt;br /&gt;            g.Dispose();&lt;br /&gt;            bitmap.Save(Server.MapPath("TextBorderShadow.png"), System.Drawing.Imaging.ImageFormat.Png);&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;    }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-8008541791995889229?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/8008541791995889229/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=8008541791995889229' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/8008541791995889229'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/8008541791995889229'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/12/draw-string-in-fix-rectangle-with_1988.html' title='DRAW STRING IN FIX RECTANGLE WITH BACKGROUNG COLOR, BORDER AND SHADOW'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-6267280354389762735</id><published>2008-12-01T02:46:00.001-08:00</published><updated>2008-12-01T03:08:37.709-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Graphics GDI+'/><title type='text'>DRAW STRING IN FIX RECTANGLE WITH BACKGROUNG COLOR AND SHADOW</title><content type='html'>using System.Drawing;&lt;br /&gt;using System.Drawing.Imaging;&lt;br /&gt;using System.Drawing.Text;&lt;br /&gt;using System.Runtime.InteropServices;&lt;br /&gt;using System.Drawing.Drawing2D;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;// CREATE ENUM FOR SHADOW STYLE&lt;br /&gt;    enum ShadowStyle&lt;br /&gt;    {&lt;br /&gt;        Top_Left,&lt;br /&gt;        Top_Right,&lt;br /&gt;        Bottom_Left,&lt;br /&gt;        Bottom_Right,&lt;br /&gt;        None&lt;br /&gt;    }&lt;br /&gt;    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (!IsPostBack)&lt;br /&gt;        {&lt;br /&gt;            Color fontColor = Color.Red;&lt;br /&gt;            Color shadowColor = Color.Blue; // SET SHADOW COLOR&lt;br /&gt;            Color bg_Color = Color.Black;&lt;br /&gt;&lt;br /&gt;            bool fontBold = false;&lt;br /&gt;            bool fontItalic = false;&lt;br /&gt;            bool fontUnderline = false;&lt;br /&gt;&lt;br /&gt;            string text = "WELCOME";&lt;br /&gt;            string fontFamily = "impact";&lt;br /&gt;            int w = 600;&lt;br /&gt;            int h = 200;&lt;br /&gt;&lt;br /&gt;            ShadowStyle shd = ShadowStyle.Top_Left; // SET SHADOW STYLE Top_Left,Top_Right,Bottom_Left, Bottom_Right and None&lt;br /&gt;&lt;br /&gt;            SolidBrush color;&lt;br /&gt;            FontStyle fontStyle = FontStyle.Regular;&lt;br /&gt;            if (fontBold) fontStyle |= FontStyle.Bold;&lt;br /&gt;            if (fontItalic) fontStyle |= FontStyle.Italic;&lt;br /&gt;            if (fontUnderline) fontStyle |= FontStyle.Underline;&lt;br /&gt;&lt;br /&gt;            Rectangle target = new Rectangle(0, 0, w, h);&lt;br /&gt;            Bitmap bitmap = new Bitmap(w, h);&lt;br /&gt;            Graphics g = Graphics.FromImage(bitmap);&lt;br /&gt;&lt;br /&gt;            color = new SolidBrush(bg_Color);&lt;br /&gt;            g.FillRectangle(color, target);&lt;br /&gt;            g.SmoothingMode = SmoothingMode.AntiAlias;&lt;br /&gt;            g.InterpolationMode = InterpolationMode.HighQualityBicubic;&lt;br /&gt;            g.PixelOffsetMode = PixelOffsetMode.HighQuality;&lt;br /&gt;&lt;br /&gt;            int trgheight = target.Height;&lt;br /&gt;            int x = 3, y = 3;&lt;br /&gt;            int tLeft = target.Left + x;&lt;br /&gt;            int tTop = target.Top + x;&lt;br /&gt;            int tRight = target.Right - x;&lt;br /&gt;            int tBottom = target.Bottom - x;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            Font the_font = new Font(fontFamily, trgheight, fontStyle, GraphicsUnit.Pixel);&lt;br /&gt;&lt;br /&gt;            StringFormat sf = new StringFormat();&lt;br /&gt;            sf.LineAlignment = StringAlignment.Center;&lt;br /&gt;            sf.Alignment = StringAlignment.Center;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            GraphicsPath text_path = new GraphicsPath();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            /* Shadow Style */&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            if (shd != ShadowStyle.None)&lt;br /&gt;            {&lt;br /&gt;                text_path.AddString(text, the_font.FontFamily, (int)fontStyle, trgheight, new PointF(0, 0), sf);&lt;br /&gt;                RectangleF text_rectf1 = text_path.GetBounds();&lt;br /&gt;                PointF[] target_pts1 = new PointF[3];&lt;br /&gt;                switch (shd)&lt;br /&gt;                {&lt;br /&gt;                    case ShadowStyle.Top_Right:&lt;br /&gt;                        target_pts1[0] = new PointF(tLeft + y, tTop - y);&lt;br /&gt;                        target_pts1[1] = new PointF(tRight + y, tTop - y);&lt;br /&gt;                        target_pts1[2] = new PointF(tLeft + y, tBottom - y);&lt;br /&gt;                        break;&lt;br /&gt;                    case ShadowStyle.Top_Left:&lt;br /&gt;                        target_pts1[0] = new PointF(tLeft - y, tTop - y);&lt;br /&gt;                        target_pts1[1] = new PointF(tRight - y, tTop - y);&lt;br /&gt;                        target_pts1[2] = new PointF(tLeft - y, tBottom - y);&lt;br /&gt;                        break;&lt;br /&gt;                    case ShadowStyle.Bottom_Right:&lt;br /&gt;                        target_pts1[0] = new PointF(tLeft + y, tTop + y);&lt;br /&gt;                        target_pts1[1] = new PointF(tRight + y, tTop + y);&lt;br /&gt;                        target_pts1[2] = new PointF(tLeft + y, tBottom + y);&lt;br /&gt;                        break;&lt;br /&gt;                    case ShadowStyle.Bottom_Left:&lt;br /&gt;                        target_pts1[0] = new PointF(tLeft - y, tTop + y);&lt;br /&gt;                        target_pts1[1] = new PointF(tRight - y, tTop + y);&lt;br /&gt;                        target_pts1[2] = new PointF(tLeft - y, tBottom + y);&lt;br /&gt;                        break;&lt;br /&gt;                    default:&lt;br /&gt;                        target_pts1[0] = new PointF(tLeft, tTop);&lt;br /&gt;                        target_pts1[1] = new PointF(tRight, tTop);&lt;br /&gt;                        target_pts1[2] = new PointF(tLeft, tBottom);&lt;br /&gt;                        break;&lt;br /&gt;                }&lt;br /&gt;                color = new SolidBrush(shadowColor);&lt;br /&gt;                g.Transform = new Matrix(text_rectf1, target_pts1);&lt;br /&gt;                g.FillPath(color, text_path);&lt;br /&gt;                text_path = new GraphicsPath();&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            /* Draw Text */&lt;br /&gt;&lt;br /&gt;            text_path.AddString(text, the_font.FontFamily, (int)fontStyle, trgheight, new PointF(0, 0), sf);&lt;br /&gt;            RectangleF text_rectf = text_path.GetBounds();&lt;br /&gt;&lt;br /&gt;            PointF[] target_pts = new PointF[3];&lt;br /&gt;            switch (shd)&lt;br /&gt;            {&lt;br /&gt;                case ShadowStyle.Top_Right:&lt;br /&gt;                    target_pts[0] = new PointF(tLeft, tTop + y);&lt;br /&gt;                    target_pts[1] = new PointF(tRight - y, tTop + y);&lt;br /&gt;                    target_pts[2] = new PointF(tLeft, tBottom);&lt;br /&gt;                    break;&lt;br /&gt;                case ShadowStyle.Top_Left:&lt;br /&gt;                    target_pts[0] = new PointF(tLeft + y, tTop + y);&lt;br /&gt;                    target_pts[1] = new PointF(tRight + y, tTop + y);&lt;br /&gt;                    target_pts[2] = new PointF(tLeft + y, tBottom);&lt;br /&gt;                    break;&lt;br /&gt;                case ShadowStyle.Bottom_Right:&lt;br /&gt;                    target_pts[0] = new PointF(tLeft, tTop - y);&lt;br /&gt;                    target_pts[1] = new PointF(tRight - y, tTop - y);&lt;br /&gt;                    target_pts[2] = new PointF(tLeft, tBottom);&lt;br /&gt;                    break;&lt;br /&gt;                case ShadowStyle.Bottom_Left:&lt;br /&gt;                    target_pts[0] = new PointF(tLeft + y, tTop - y);&lt;br /&gt;                    target_pts[1] = new PointF(tRight + y, tTop - y);&lt;br /&gt;                    target_pts[2] = new PointF(tLeft + y, tBottom);&lt;br /&gt;                    break;&lt;br /&gt;                default:&lt;br /&gt;                    target_pts[0] = new PointF(tLeft, tTop);&lt;br /&gt;                    target_pts[1] = new PointF(tRight, tTop);&lt;br /&gt;                    target_pts[2] = new PointF(tLeft, tBottom);&lt;br /&gt;                    break;&lt;br /&gt;            }&lt;br /&gt;            g.Transform = new Matrix(text_rectf, target_pts);&lt;br /&gt;&lt;br /&gt;            color = new SolidBrush(fontColor);&lt;br /&gt;            g.FillPath(color, text_path);&lt;br /&gt;            g.ResetTransform();&lt;br /&gt;            text_path.Dispose();&lt;br /&gt;            sf.Dispose();&lt;br /&gt;            the_font.Dispose();&lt;br /&gt;            g.Dispose();&lt;br /&gt;            bitmap.Save(Server.MapPath("TextWithShadow.png"), System.Drawing.Imaging.ImageFormat.Png);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;    }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-6267280354389762735?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/6267280354389762735/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=6267280354389762735' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/6267280354389762735'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/6267280354389762735'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/12/draw-string-in-fix-rectangle-with_01.html' title='DRAW STRING IN FIX RECTANGLE WITH BACKGROUNG COLOR AND SHADOW'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-5941824627826386587</id><published>2008-12-01T02:19:00.000-08:00</published><updated>2008-12-01T04:03:04.568-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Graphics GDI+'/><title type='text'>DRAW STRING IN FIX RECTANGLE WITH BACKGROUNG COLOR AND BORDER</title><content type='html'>using System.Drawing;&lt;br /&gt;using System.Drawing.Imaging;&lt;br /&gt;using System.Drawing.Text;&lt;br /&gt;using System.Runtime.InteropServices;&lt;br /&gt;using System.Drawing.Drawing2D;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (!IsPostBack)&lt;br /&gt;        {&lt;br /&gt;            Color fontColor = Color.Red; // SET FONT COLOR&lt;br /&gt;            Color bg_Color = Color.Black; // SET BACKGROUNG COLOR&lt;br /&gt;            Color borderColor = Color.Yellow; // SET BORDER COLOR&lt;br /&gt;&lt;br /&gt;            bool fontBold = false;&lt;br /&gt;            bool fontItalic = false;&lt;br /&gt;            bool fontUnderline = false;&lt;br /&gt;&lt;br /&gt;            string text = "WELCOME"; // TEXT&lt;br /&gt;            string fontFamily = "impact"; // FONT FAMILY&lt;br /&gt;&lt;br /&gt;            int w = 600; // IMAGE WIDTH&lt;br /&gt;            int h = 300; // IMAGE HEIGHT&lt;br /&gt;&lt;br /&gt;            int borderWidth = 3;&lt;br /&gt;&lt;br /&gt;            SolidBrush color;&lt;br /&gt;            FontStyle fontStyle = FontStyle.Regular;&lt;br /&gt;            if (fontBold) fontStyle |= FontStyle.Bold;&lt;br /&gt;            if (fontItalic) fontStyle |= FontStyle.Italic;&lt;br /&gt;            if (fontUnderline) fontStyle |= FontStyle.Underline;&lt;br /&gt;&lt;br /&gt;            Rectangle target = new Rectangle(0, 0, w, h); // GET TARGET RECTANGLE&lt;br /&gt;            Bitmap bitmap = new Bitmap(w, h);&lt;br /&gt;            Graphics g = Graphics.FromImage(bitmap);&lt;br /&gt;            color = new SolidBrush(bg_Color);&lt;br /&gt;            g.FillRectangle(color, target); // FILL BACKGROUND&lt;br /&gt;            g.SmoothingMode = SmoothingMode.AntiAlias;&lt;br /&gt;            g.InterpolationMode = InterpolationMode.HighQualityBicubic;&lt;br /&gt;            g.PixelOffsetMode = PixelOffsetMode.HighQuality;&lt;br /&gt;&lt;br /&gt;            int trgheight = target.Height;&lt;br /&gt;            int x = 3; // LEAVE SPACE TO LEFT,TOP,RIGHT AND BOTTOM OF IMAGE&lt;br /&gt;            int tLeft = target.Left + x;&lt;br /&gt;            int tTop = target.Top + x;&lt;br /&gt;            int tRight = target.Right - x;&lt;br /&gt;            int tBottom = target.Bottom - x;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            Font the_font = new Font(fontFamily, trgheight, fontStyle, GraphicsUnit.Pixel);&lt;br /&gt;&lt;br /&gt;            StringFormat sf = new StringFormat();&lt;br /&gt;            sf.LineAlignment = StringAlignment.Center;&lt;br /&gt;            sf.Alignment = StringAlignment.Center;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            GraphicsPath text_path = new GraphicsPath();&lt;br /&gt;&lt;br /&gt;            text_path.AddString(text, the_font.FontFamily, (int)fontStyle, trgheight, new PointF(0, 0), sf);&lt;br /&gt;            RectangleF text_rectf = text_path.GetBounds();&lt;br /&gt;&lt;br /&gt;            PointF[] target_pts = new PointF[3];&lt;br /&gt;            target_pts[0] = new PointF(tLeft, tTop);&lt;br /&gt;            target_pts[1] = new PointF(tRight, tTop);&lt;br /&gt;            target_pts[2] = new PointF(tLeft, tBottom);&lt;br /&gt;            //GET POINTS TO DRAW TEXT INTO RECTANGLE&lt;br /&gt;&lt;br /&gt;            g.Transform = new Matrix(text_rectf, target_pts);&lt;br /&gt;&lt;br /&gt;            color = new SolidBrush(fontColor);&lt;br /&gt;            g.FillPath(color, text_path);&lt;br /&gt;&lt;br /&gt;            color = new SolidBrush(borderColor);&lt;br /&gt;            Pen pen = new Pen(color);&lt;br /&gt;            for (int i = 0; i &lt;= borderWidth; i++)&lt;br /&gt;            {&lt;br /&gt;                for (int j = 0; j &lt;= borderWidth; j++)&lt;br /&gt;                {&lt;br /&gt;                    text_path.AddString(text, the_font.FontFamily, (int)fontStyle, target.Height, new PointF(i, j), sf);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            g.DrawPath(pen, text_path); // DRAW BORDER&lt;br /&gt;            g.ResetTransform();&lt;br /&gt;            text_path.Dispose();&lt;br /&gt;            sf.Dispose();&lt;br /&gt;            the_font.Dispose();&lt;br /&gt;            g.Dispose();&lt;br /&gt;            bitmap.Save(Server.MapPath("TextWithBorder.png"), System.Drawing.Imaging.ImageFormat.Png); //  SAVE IMAGE TO THE ROOT &lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;    }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-5941824627826386587?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/5941824627826386587/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=5941824627826386587' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/5941824627826386587'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/5941824627826386587'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/12/draw-text-into-fix-rectangle-with.html' title='DRAW STRING IN FIX RECTANGLE WITH BACKGROUNG COLOR AND BORDER'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-5120339097604359587</id><published>2008-12-01T02:15:00.000-08:00</published><updated>2008-12-01T03:08:37.710-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Graphics GDI+'/><title type='text'>DRAW STRING IN FIX RECTANGLE WITH BACKGROUNG COLOR</title><content type='html'>using System.Drawing;&lt;br /&gt;using System.Drawing.Imaging;&lt;br /&gt;using System.Drawing.Text;&lt;br /&gt;using System.Runtime.InteropServices;&lt;br /&gt;using System.Drawing.Drawing2D;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (!IsPostBack)&lt;br /&gt;        {&lt;br /&gt;            Color fontColor = Color.Red; // SET FONT COLOR&lt;br /&gt;            Color bg_Color = Color.Black; // SET BACKGROUNG COLOR&lt;br /&gt;            bool fontBold = false;&lt;br /&gt;            bool fontItalic = false;&lt;br /&gt;            bool fontUnderline = false;&lt;br /&gt;            string text = "WELCOME"; // TEXT&lt;br /&gt;&lt;br /&gt;            string fontFamily = "impact"; // FONT FAMILY&lt;br /&gt;            int w = 600; // IMAGE WIDTH&lt;br /&gt;            int h = 300; // IMAGE HEIGHT&lt;br /&gt;&lt;br /&gt;            SolidBrush color;&lt;br /&gt;            FontStyle fontStyle = FontStyle.Regular;&lt;br /&gt;            if (fontBold) fontStyle |= FontStyle.Bold;&lt;br /&gt;            if (fontItalic) fontStyle |= FontStyle.Italic;&lt;br /&gt;            if (fontUnderline) fontStyle |= FontStyle.Underline;&lt;br /&gt;&lt;br /&gt;            Rectangle target = new Rectangle(0, 0, w, h); // GET TARGET RECTANGLE&lt;br /&gt;            Bitmap bitmap = new Bitmap(w, h);&lt;br /&gt;            Graphics g = Graphics.FromImage(bitmap);&lt;br /&gt;            color = new SolidBrush(bg_Color);&lt;br /&gt;            g.FillRectangle(color, target); // FILL BACKGROUND&lt;br /&gt;            g.SmoothingMode = SmoothingMode.AntiAlias;&lt;br /&gt;            g.InterpolationMode = InterpolationMode.HighQualityBicubic;&lt;br /&gt;            g.PixelOffsetMode = PixelOffsetMode.HighQuality;&lt;br /&gt;&lt;br /&gt;            int trgheight = target.Height;&lt;br /&gt;            int x = 3; // LEAVE SPACE TO LEFT,TOP,RIGHT AND BOTTOM OF IMAGE&lt;br /&gt;            int tLeft = target.Left + x;&lt;br /&gt;            int tTop = target.Top + x;&lt;br /&gt;            int tRight = target.Right - x;&lt;br /&gt;            int tBottom = target.Bottom - x;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            Font the_font = new Font(fontFamily, trgheight, fontStyle, GraphicsUnit.Pixel);&lt;br /&gt;&lt;br /&gt;            StringFormat sf = new StringFormat();&lt;br /&gt;            sf.LineAlignment = StringAlignment.Center;&lt;br /&gt;            sf.Alignment = StringAlignment.Center;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            GraphicsPath text_path = new GraphicsPath();&lt;br /&gt;&lt;br /&gt;            text_path.AddString(text, the_font.FontFamily, (int)fontStyle, trgheight, new PointF(0, 0), sf);&lt;br /&gt;            RectangleF text_rectf = text_path.GetBounds();&lt;br /&gt;&lt;br /&gt;            PointF[] target_pts = new PointF[3];&lt;br /&gt;            target_pts[0] = new PointF(tLeft, tTop);&lt;br /&gt;            target_pts[1] = new PointF(tRight, tTop);&lt;br /&gt;            target_pts[2] = new PointF(tLeft, tBottom);&lt;br /&gt;            //GET POINTS TO DRAW TEXT INTO RECTANGLE&lt;br /&gt;&lt;br /&gt;            g.Transform = new Matrix(text_rectf, target_pts);&lt;br /&gt;&lt;br /&gt;            color = new SolidBrush(fontColor);&lt;br /&gt;            g.FillPath(color, text_path);&lt;br /&gt;&lt;br /&gt;            g.ResetTransform();&lt;br /&gt;            text_path.Dispose();&lt;br /&gt;            sf.Dispose();&lt;br /&gt;            the_font.Dispose();&lt;br /&gt;            g.Dispose();&lt;br /&gt;            bitmap.Save(Server.MapPath("TextWithBG.png"), System.Drawing.Imaging.ImageFormat.Png); //  SAVE IMAGE TO THE ROOT &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;    }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-5120339097604359587?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/5120339097604359587/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=5120339097604359587' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/5120339097604359587'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/5120339097604359587'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/12/draw-string-in-fix-rectangle-with.html' title='DRAW STRING IN FIX RECTANGLE WITH BACKGROUNG COLOR'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-2639908528849726901</id><published>2008-12-01T01:59:00.000-08:00</published><updated>2008-12-01T03:08:37.710-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Graphics GDI+'/><title type='text'>DRAW STRING IN FIX RECTANGLE</title><content type='html'>using System.Drawing;&lt;br /&gt;using System.Drawing.Imaging;&lt;br /&gt;using System.Drawing.Text;&lt;br /&gt;using System.Runtime.InteropServices;&lt;br /&gt;using System.Drawing.Drawing2D;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (!IsPostBack)&lt;br /&gt;        {&lt;br /&gt;            Color fontColor = Color.Red; // SET FONT COLOR&lt;br /&gt;            bool fontBold = false;&lt;br /&gt;            bool fontItalic = false;&lt;br /&gt;            bool fontUnderline = false;&lt;br /&gt;            string text = "WELCOME"; // TEXT&lt;br /&gt;&lt;br /&gt;            string fontFamily = "impact"; // FONT FAMILY&lt;br /&gt;            int w = 600; // IMAGE WIDTH&lt;br /&gt;            int h = 300; // IMAGE HEIGHT&lt;br /&gt;&lt;br /&gt;            SolidBrush color;&lt;br /&gt;            FontStyle fontStyle = FontStyle.Regular;&lt;br /&gt;            if (fontBold) fontStyle |= FontStyle.Bold;&lt;br /&gt;            if (fontItalic) fontStyle |= FontStyle.Italic;&lt;br /&gt;            if (fontUnderline) fontStyle |= FontStyle.Underline;&lt;br /&gt;&lt;br /&gt;            Rectangle target = new Rectangle(0, 0, w, h); // GET TARGET RECTANGLE&lt;br /&gt;            Bitmap bitmap = new Bitmap(w, h);&lt;br /&gt;            Graphics g = Graphics.FromImage(bitmap);&lt;br /&gt;&lt;br /&gt;            g.SmoothingMode = SmoothingMode.AntiAlias;&lt;br /&gt;            g.InterpolationMode = InterpolationMode.HighQualityBicubic;&lt;br /&gt;            g.PixelOffsetMode = PixelOffsetMode.HighQuality;&lt;br /&gt;&lt;br /&gt;            int trgheight = target.Height;&lt;br /&gt;            int x = 3; // LEAVE SPACE TO LEFT,TOP,RIGHT AND BOTTOM OF IMAGE&lt;br /&gt;            int tLeft = target.Left + x;&lt;br /&gt;            int tTop = target.Top + x;&lt;br /&gt;            int tRight = target.Right - x;&lt;br /&gt;            int tBottom = target.Bottom - x;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            Font the_font = new Font(fontFamily, trgheight, fontStyle, GraphicsUnit.Pixel);&lt;br /&gt;&lt;br /&gt;            StringFormat sf = new StringFormat();&lt;br /&gt;            sf.LineAlignment = StringAlignment.Center;&lt;br /&gt;            sf.Alignment = StringAlignment.Center;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;            GraphicsPath text_path = new GraphicsPath();&lt;br /&gt;&lt;br /&gt;            text_path.AddString(text, the_font.FontFamily, (int)fontStyle, trgheight, new PointF(0, 0), sf);&lt;br /&gt;            RectangleF text_rectf = text_path.GetBounds();&lt;br /&gt;&lt;br /&gt;            PointF[] target_pts = new PointF[3];&lt;br /&gt;            target_pts[0] = new PointF(tLeft, tTop);&lt;br /&gt;            target_pts[1] = new PointF(tRight, tTop);&lt;br /&gt;            target_pts[2] = new PointF(tLeft, tBottom);&lt;br /&gt;            //GET POINTS TO DRAW TEXT INTO RECTANGLE&lt;br /&gt;&lt;br /&gt;            g.Transform = new Matrix(text_rectf, target_pts);&lt;br /&gt;&lt;br /&gt;            color = new SolidBrush(fontColor);&lt;br /&gt;            g.FillPath(color, text_path);&lt;br /&gt;&lt;br /&gt;            g.ResetTransform();&lt;br /&gt;            text_path.Dispose();&lt;br /&gt;            sf.Dispose();&lt;br /&gt;            the_font.Dispose();&lt;br /&gt;            g.Dispose();&lt;br /&gt;            bitmap.Save(Server.MapPath("MyImage.png"), System.Drawing.Imaging.ImageFormat.Png); //  SAVE IMAGE TO THE ROOT &lt;br /&gt;&lt;br /&gt;        }&lt;br /&gt;    }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-2639908528849726901?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/2639908528849726901/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=2639908528849726901' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/2639908528849726901'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/2639908528849726901'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/12/draw-string-in-fix-rectangle.html' title='DRAW STRING IN FIX RECTANGLE'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-1381153452981192202</id><published>2008-10-08T00:03:00.000-07:00</published><updated>2008-12-01T03:09:53.011-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Other'/><title type='text'>Generate Random String</title><content type='html'>Below function generate random string.&lt;br /&gt;&lt;br /&gt;private string RandomString(int size, bool lowerCase)&lt;br /&gt;    {&lt;br /&gt;        StringBuilder builder = new StringBuilder();&lt;br /&gt;        Random random = new Random();&lt;br /&gt;        char ch;&lt;br /&gt;        int val;&lt;br /&gt;        for (int i = 0; i &lt; size; i++)&lt;br /&gt;        {&lt;br /&gt;            ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));&lt;br /&gt;            //val = random.Next(0, 9);&lt;br /&gt;            builder.Append(ch.ToString());&lt;br /&gt;        }&lt;br /&gt;        if (lowerCase)&lt;br /&gt;          return builder.ToString().ToLower();&lt;br /&gt;        return builder.ToString();&lt;br /&gt;    }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-1381153452981192202?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/1381153452981192202/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=1381153452981192202' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/1381153452981192202'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/1381153452981192202'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/10/generate-random-string.html' title='Generate Random String'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-4200141724406171018</id><published>2008-09-26T04:34:00.001-07:00</published><updated>2008-12-12T04:58:34.789-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Data Control'/><title type='text'>Custom Paging in GridView, DataList or Repeater Using Stored Procedure.</title><content type='html'>First of all of I have created table named tblEmployee as belove figure.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Using Row_Number : Returns the sequential number of a row within a partition of a result set, starting at 1 for the first row in each partition.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;Query : select *,ROW_NUMBER() over(Order By Name) as PageNum from tblEmployee&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This query generates one extra column as PageNum title and it contains index of data row starting at 1for the first row.&lt;br /&gt;&lt;br /&gt;Now to perform Paging in store procedure, I Pass two parameter @PageIndex and @PageSizes and get back total number of cecords in the table as out parameter.&lt;br /&gt;&lt;br /&gt;Store Procedure&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;CREATE PROCEDURE usp_List_Employees&lt;br /&gt; &lt;br /&gt; (&lt;br /&gt;  @pageIndex int,&lt;br /&gt;  @PageSize int,&lt;br /&gt;  @OutParameter int out&lt;br /&gt; )&lt;br /&gt; &lt;br /&gt;AS&lt;br /&gt; &lt;br /&gt; Select * from &lt;br /&gt; (&lt;br /&gt;  select *,ROW_NUMBER() over(Order By Name) as PageNum&lt;br /&gt;  from tblEmployee&lt;br /&gt; ) &lt;br /&gt;  as tblEmployee&lt;br /&gt; where PageNum Between (@PageIndex - 1)  *  @PageSize + 1 and @PageIndex  *  @PageSize&lt;br /&gt; &lt;br /&gt; select @outParameter=count(*) from tblEmployee&lt;br /&gt; &lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Inline code&lt;br /&gt;&lt;code&gt;&lt;br /&gt; &amp;lt;table cellpadding="5" cellspacing="2" width="400px"&amp;gt;&lt;br /&gt;            &amp;lt;tr&amp;gt;&lt;br /&gt;                &amp;lt;td colspan="8"&amp;gt;&lt;br /&gt;                    &amp;lt;asp:GridView ID="grid" runat="server" AutoGenerateColumns="False" CellPadding="4"&lt;br /&gt;                        ForeColor="#333333" GridLines="None" Height="184px" Width="491px"&amp;gt;&lt;br /&gt;                        &amp;lt;FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" /&amp;gt;&lt;br /&gt;                        &amp;lt;RowStyle ForeColor="#333333" BackColor="#F7F6F3" HorizontalAlign="left" /&amp;gt;&lt;br /&gt;                        &amp;lt;SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /&amp;gt;&lt;br /&gt;                        &amp;lt;PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /&amp;gt;&lt;br /&gt;                        &amp;lt;HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" HorizontalAlign="left" /&amp;gt;&lt;br /&gt;                        &amp;lt;Columns&amp;gt;&lt;br /&gt;                            &amp;lt;asp:TemplateField HeaderText="Sr.No"&amp;gt;&lt;br /&gt;                                &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;                                    &amp;lt;%# Eval("PageNum") %&amp;gt;&lt;br /&gt;                                &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;                            &amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;                            &amp;lt;asp:TemplateField HeaderText="Employee Name"&amp;gt;&lt;br /&gt;                                &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;                                    &amp;lt;%#Eval("Name") %&amp;gt;&lt;br /&gt;                                &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;                            &amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;                            &amp;lt;asp:TemplateField HeaderText="Email Address"&amp;gt;&lt;br /&gt;                                &amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;                                    &amp;lt;%#Eval("Email") %&amp;gt;&lt;br /&gt;                                &amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;                            &amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;                        &amp;lt;/Columns&amp;gt;&lt;br /&gt;                        &amp;lt;EditRowStyle BackColor="#999999" /&amp;gt;&lt;br /&gt;                        &amp;lt;AlternatingRowStyle BackColor="White" ForeColor="#284775" /&amp;gt;&lt;br /&gt;                    &amp;lt;/asp:GridView&amp;gt;&lt;br /&gt;                &amp;lt;/td&amp;gt;&lt;br /&gt;            &amp;lt;/tr&amp;gt;&lt;br /&gt;            &amp;lt;tr&amp;gt;&lt;br /&gt;                &amp;lt;td width="10px"&amp;gt;&lt;br /&gt;                    &amp;lt;asp:LinkButton ID="lnkFirst" runat="server" Text="First" OnClick="Paging_Event"&amp;gt;&amp;lt;/asp:LinkButton&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;                &amp;lt;td width="10px"&amp;gt;&lt;br /&gt;                    &amp;lt;asp:LinkButton ID="lnkPre" runat="server" Text="Pre" OnClick="Paging_Event"&amp;gt;&amp;lt;/asp:LinkButton&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;                &amp;lt;td width="10px"&amp;gt;&lt;br /&gt;                    &amp;lt;asp:LinkButton ID="lnkNext" runat="server" Text="Next" OnClick="Paging_Event"&amp;gt;&amp;lt;/asp:LinkButton&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;                &amp;lt;td width="10px"&amp;gt;&lt;br /&gt;                    &amp;lt;asp:LinkButton ID="lnkLast" runat="Server" Text="Last" OnClick="Paging_Event"&amp;gt;&amp;lt;/asp:LinkButton&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;                &amp;lt;td width="100px"&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;                &amp;lt;td&amp;gt;&lt;br /&gt;                    Page&amp;nbsp;&amp;lt;asp:Label ID="lblPageNo" runat="server"&amp;gt;&amp;lt;/asp:Label&amp;gt;&amp;nbsp;of&amp;nbsp;&lt;br /&gt;                    &amp;lt;asp:Label ID="lblTotalPage" runat="server"&amp;gt;&amp;lt;/asp:Label&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;                &amp;lt;td&amp;gt;&lt;br /&gt;                &amp;lt;/td&amp;gt;&lt;br /&gt;                &amp;lt;td align="right"&amp;gt;&lt;br /&gt;                    Jump to&amp;nbsp;&amp;lt;asp:DropDownList ID="ddl" runat="server" AutoPostBack="true" OnSelectedIndexChanged="Jump_ToPaging"&amp;gt;&lt;br /&gt;                    &amp;lt;/asp:DropDownList&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;            &amp;lt;/tr&amp;gt;&lt;br /&gt;        &amp;lt;/table&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; code behind&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt; &amp;lt;add key="conString" value="server=ServerName; Data Source=DataSourceName; uid=username pw=password"/&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt; using System.Data.SqlClient;&lt;br /&gt; &lt;/code&gt;&lt;br /&gt; &lt;code&gt;&lt;br /&gt;    private string conString = System.Configuration.ConfigurationManager.AppSettings["conString"];&lt;br /&gt;    private int currentPageIndex = 1;&lt;br /&gt;    private int pageSize = 5;&lt;br /&gt;    private int totalRecords=0;&lt;br /&gt;    private double totalPage = 0;&lt;br /&gt;    &lt;/code&gt;&lt;br /&gt;  &lt;code&gt;&lt;br /&gt;    protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (!IsPostBack)&lt;br /&gt;        {&lt;br /&gt;            bind_Employees();&lt;br /&gt;            BindPageIndex();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;/code&gt;&lt;br /&gt;    &lt;code&gt;&lt;br /&gt;    public void bind_Employees()&lt;br /&gt;    {&lt;br /&gt;        grid.DataSource = GetData();&lt;br /&gt;        grid.DataBind();&lt;br /&gt;        PageSetting();&lt;br /&gt;    }&lt;br /&gt;    &lt;/code&gt;&lt;br /&gt;    &lt;code&gt;&lt;br /&gt;    public void PageSetting()&lt;br /&gt;    {&lt;br /&gt;        totalPage = Convert.ToDouble(totalRecords) / pageSize;&lt;br /&gt;        totalPage = System.Math.Ceiling(totalPage);&lt;br /&gt;        lblPageNo.Text = totalPage == 0 ? "0" : currentPageIndex.ToString();&lt;br /&gt;        lblTotalPage.Text = totalPage.ToString();&lt;br /&gt;        &lt;br /&gt;        &lt;br /&gt;        if (currentPageIndex == 1)&lt;br /&gt;        {&lt;br /&gt;            lnkFirst.Enabled = false;&lt;br /&gt;            lnkPre.Enabled = false;&lt;br /&gt;        }&lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            lnkFirst.Enabled = true;&lt;br /&gt;            lnkPre.Enabled = true;&lt;br /&gt;        }&lt;br /&gt;        if (totalPage &gt; 1)&lt;br /&gt;        {&lt;br /&gt;            if (currentPageIndex != totalPage)&lt;br /&gt;            {&lt;br /&gt;                lnkNext.Enabled = true;&lt;br /&gt;                lnkLast.Enabled = true;&lt;br /&gt;            }&lt;br /&gt;            else&lt;br /&gt;            {&lt;br /&gt;                lnkNext.Enabled = false;&lt;br /&gt;                lnkLast.Enabled = false;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            lnkNext.Enabled = false;&lt;br /&gt;            lnkLast.Enabled = false;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;/code&gt;&lt;br /&gt;    &lt;code&gt;&lt;br /&gt;    public void BindPageIndex()&lt;br /&gt;    {&lt;br /&gt;        ddl.Items.Clear();&lt;br /&gt;        for (int i = 1; i &lt;= totalPage; i++)&lt;br /&gt;        {&lt;br /&gt;            ddl.Items.Add(new ListItem(i.ToString(), i.ToString()));&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;/code&gt;&lt;br /&gt;    &lt;code&gt;&lt;br /&gt;    public DataSet GetData()&lt;br /&gt;    {&lt;br /&gt;        SqlConnection con = new SqlConnection(conString);&lt;br /&gt;        SqlCommand cmd = new SqlCommand();&lt;br /&gt;        cmd.CommandText = "usp_List_Employees";&lt;br /&gt;        cmd.CommandType = CommandType.StoredProcedure;&lt;br /&gt;        cmd.Connection = con;&lt;br /&gt;        &lt;br /&gt;        SqlParameter prm = new SqlParameter();&lt;br /&gt;        prm.ParameterName = "@pageIndex";&lt;br /&gt;        prm.Direction = ParameterDirection.Input;&lt;br /&gt;        prm.SqlDbType = SqlDbType.Int;&lt;br /&gt;        prm.SqlValue = currentPageIndex.ToString();&lt;br /&gt;        cmd.Parameters.Add(prm);&lt;br /&gt;&lt;br /&gt;        prm = new SqlParameter();&lt;br /&gt;        prm.ParameterName = "@PageSize";&lt;br /&gt;        prm.Direction = ParameterDirection.Input;&lt;br /&gt;        prm.SqlDbType = SqlDbType.Int;&lt;br /&gt;        prm.SqlValue = pageSize;&lt;br /&gt;        cmd.Parameters.Add(prm);&lt;br /&gt;&lt;br /&gt;        prm = new SqlParameter();&lt;br /&gt;        prm.ParameterName = "@OutParameter";&lt;br /&gt;        prm.Direction = ParameterDirection.Output;&lt;br /&gt;        prm.SqlDbType = SqlDbType.Int;&lt;br /&gt;        cmd.Parameters.Add(prm);&lt;br /&gt;&lt;br /&gt;        &lt;br /&gt;        SqlDataAdapter adp = new SqlDataAdapter(cmd);&lt;br /&gt;        DataSet ds = new DataSet();&lt;br /&gt;        adp.Fill(ds);&lt;br /&gt;        totalRecords = int.Parse(cmd.Parameters["@OutParameter"].Value.ToString());&lt;br /&gt;        return ds;&lt;br /&gt;    }&lt;br /&gt;    &lt;/code&gt;&lt;br /&gt;    &lt;code&gt;&lt;br /&gt;    protected void Paging_Event(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        switch (((LinkButton)sender).ID)&lt;br /&gt;        {&lt;br /&gt;            case "lnkFirst":&lt;br /&gt;                currentPageIndex = 1;&lt;br /&gt;                break;&lt;br /&gt;            case "lnkLast":&lt;br /&gt;                currentPageIndex = Int32.Parse(lblTotalPage.Text);&lt;br /&gt;                break;&lt;br /&gt;            case "lnkNext":&lt;br /&gt;                currentPageIndex = Int32.Parse(lblPageNo.Text) + 1;&lt;br /&gt;                break;&lt;br /&gt;            case "lnkPre":&lt;br /&gt;                currentPageIndex = Int32.Parse(lblPageNo.Text) - 1;&lt;br /&gt;                break;&lt;br /&gt;        }&lt;br /&gt;        bind_Employees();&lt;br /&gt;        ddl.SelectedValue = currentPageIndex.ToString();&lt;br /&gt;    }&lt;br /&gt;  &lt;/code&gt;&lt;br /&gt;    &lt;code&gt;&lt;br /&gt;    protected void Jump_ToPaging(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        currentPageIndex = int.Parse(ddl.SelectedValue);&lt;br /&gt;        bind_Employees();&lt;br /&gt;    }&lt;br /&gt;   &lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-4200141724406171018?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/4200141724406171018/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=4200141724406171018' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/4200141724406171018'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/4200141724406171018'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/09/custom-paging-in-gridview-datalist-or.html' title='Custom Paging in GridView, DataList or Repeater Using Stored Procedure.'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-8797400799983060087</id><published>2008-09-25T04:39:00.000-07:00</published><updated>2008-12-01T03:09:53.012-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Other'/><title type='text'>Using RSS feeds in asp .net and C#</title><content type='html'>&lt;code&gt;&lt;br /&gt;using System.XML;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Gets the xml from the Url using XmlTextReader&lt;br /&gt;&lt;code&gt;&lt;br /&gt;XmlTextReader reader = new XmlTextReader("http://msdn.microsoft.com/rss.xml");&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;creates a new instance of DataSet&lt;br /&gt;&lt;code&gt;&lt;br /&gt;DataSet ds = new DataSet();&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Reads the xml into the dataset&lt;br /&gt;&lt;code&gt;&lt;br /&gt;ds.ReadXml(reader);&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Assigns the data table to the datagrid&lt;br /&gt;&lt;code&gt;&lt;br /&gt;grid.DataSource = ds.Tables[0];&lt;br /&gt;myDataGrid.DataBind(); &lt;br /&gt;&lt;/code&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-8797400799983060087?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/8797400799983060087/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=8797400799983060087' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/8797400799983060087'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/8797400799983060087'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/09/using-rss-feeds-in-asp-net-and-c.html' title='Using RSS feeds in asp .net and C#'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-1262913366073734717</id><published>2008-09-19T03:52:00.000-07:00</published><updated>2008-12-01T03:09:53.012-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Other'/><title type='text'>Programmatically Add Meta Tags in asp.net page</title><content type='html'>// Create HtmlHead object.&lt;br /&gt;HtmlHead head = (System.Web.UI.HtmlControls.HtmlHead)Header;&lt;br /&gt;&lt;br /&gt;//Create HtmlMeta Object.&lt;br /&gt;HtmlMeta meta = new HtmlMeta();&lt;br /&gt;&lt;br /&gt;//Add Attributes to Meta tags.&lt;br /&gt;meta.Attributes.Add("content", objLpa.MetaDesc);&lt;br /&gt;meta.Attributes.Add("name", "description");&lt;br /&gt;&lt;br /&gt;//Add meta tag to html header.&lt;br /&gt;head.Controls.Add(meta);&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-1262913366073734717?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/1262913366073734717/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=1262913366073734717' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/1262913366073734717'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/1262913366073734717'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/09/programmatically-add-meta-tags-in.html' title='Programmatically Add Meta Tags in asp.net page'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-8482547934611149387</id><published>2008-09-18T04:28:00.000-07:00</published><updated>2008-12-01T03:17:25.895-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Graphics GDI+'/><title type='text'>Rotate Image using c#</title><content type='html'>using System.Drawing;&lt;br /&gt;using System.Drawing.Imaging;&lt;br /&gt;using System.Drawing.Text;&lt;br /&gt;using System.Runtime.InteropServices;&lt;br /&gt;using System.Drawing.Drawing2D;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;        if (!IsPostBack)&lt;br /&gt;        {&lt;br /&gt;            Bitmap b = new Bitmap(Server.MapPath("TextWithMultilines.png"));&lt;br /&gt;            b = RotateImage(180, b); // Pass angle and bitmap object&lt;br /&gt;            b.Save(Server.MapPath("NewImage.png"), ImageFormat.Png);&lt;br /&gt;            b.Dispose();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public Bitmap RotateImage(float Angle, Bitmap bm_in)&lt;br /&gt;    {&lt;br /&gt;        try&lt;br /&gt;        {&lt;br /&gt;            float wid = bm_in.Width;&lt;br /&gt;            float hgt = bm_in.Height;&lt;br /&gt;            Point[] corners = { new Point(0, 0), new Point(int.Parse(wid.ToString()), 0), new Point(0, int.Parse(hgt.ToString())), new Point(int.Parse(wid.ToString()), int.Parse(hgt.ToString())) };&lt;br /&gt;            int cx = int.Parse(wid.ToString()) / 2;&lt;br /&gt;            int cy = int.Parse(hgt.ToString()) / 2;&lt;br /&gt;            long i;&lt;br /&gt;            for (i = 0; i &lt;= 3; i++)&lt;br /&gt;            {&lt;br /&gt;                corners[i].X -= Convert.ToInt32(cx.ToString());&lt;br /&gt;                corners[i].Y -= Convert.ToInt32(cy.ToString());&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            float theta = (float)(Angle * Math.PI / 180.0);&lt;br /&gt;            float sin_theta = (float)Math.Sin(theta);&lt;br /&gt;            float cos_theta = (float)Math.Cos(theta);&lt;br /&gt;            float X;&lt;br /&gt;            float Y;&lt;br /&gt;            for (i = 0; i &lt;= 3; i++)&lt;br /&gt;            {&lt;br /&gt;                X = corners[i].X;&lt;br /&gt;                Y = corners[i].Y;&lt;br /&gt;                corners[i].X = (int)(X * cos_theta + Y * sin_theta);&lt;br /&gt;                corners[i].Y = (int)(-X * sin_theta + Y * cos_theta);&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            float xmin = corners[0].X;&lt;br /&gt;            float ymin = corners[0].Y;&lt;br /&gt;            for (i = 1; i &lt;= 3; i++)&lt;br /&gt;            {&lt;br /&gt;                if (xmin &gt; corners[i].X)&lt;br /&gt;                    xmin = corners[i].X;&lt;br /&gt;                if (ymin &gt; corners[i].Y)&lt;br /&gt;                    ymin = corners[i].Y;&lt;br /&gt;            }&lt;br /&gt;            for (i = 0; i &lt;= 3; i++)&lt;br /&gt;            {&lt;br /&gt;                corners[i].X -= int.Parse(xmin.ToString());&lt;br /&gt;                corners[i].Y -= int.Parse(ymin.ToString());&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            Bitmap bm_out = new Bitmap((int)(-2 * xmin), (int)(-2 * ymin));&lt;br /&gt;            Graphics gr_out = Graphics.FromImage(bm_out);&lt;br /&gt;            // ERROR: Not supported in C#: ReDimStatement&lt;br /&gt;            Point[] temp = new Point[3];&lt;br /&gt;            if (corners != null)&lt;br /&gt;            {&lt;br /&gt;                Array.Copy(corners, temp, Math.Min(corners.Length, temp.Length));&lt;br /&gt;            }&lt;br /&gt;            corners = temp;&lt;br /&gt;            gr_out.DrawImage(bm_in, corners);&lt;br /&gt;            gr_out.Dispose();&lt;br /&gt;            &lt;br /&gt;            return bm_out;&lt;br /&gt;        }&lt;br /&gt;        catch (Exception ex)&lt;br /&gt;        {&lt;br /&gt;            return bm_in;&lt;br /&gt;        }&lt;br /&gt;    }&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-8482547934611149387?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/8482547934611149387/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=8482547934611149387' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/8482547934611149387'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/8482547934611149387'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/09/rotate-image-using-c.html' title='Rotate Image using c#'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9197207222512678697.post-1792950145544937882</id><published>2008-09-18T00:42:00.000-07:00</published><updated>2008-12-01T03:09:53.012-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Other'/><title type='text'>Download file from the server to local machine</title><content type='html'>&lt;span style="font-weight:bold;"&gt;In C#&lt;/span&gt;&lt;br /&gt; string FileName = Server.MapPath("MyFileName.txt"); &lt;br /&gt; Response.Clear();&lt;br /&gt;        Response.ClearContent();&lt;br /&gt;        Response.ContentType = "application/pdf";&lt;br /&gt;        Response.AddHeader("Content-Disposition", "attachment; filename=DownloadFile.txt;");&lt;br /&gt;&lt;br /&gt;        byte[] buffer = System.IO.File.ReadAllBytes(FileName);&lt;br /&gt;&lt;br /&gt;        System.IO.MemoryStream mem = new System.IO.MemoryStream();&lt;br /&gt;        mem.Write(buffer, 0, buffer.Length);&lt;br /&gt;&lt;br /&gt;        mem.WriteTo(Response.OutputStream);&lt;br /&gt;        Response.End();&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;In Vb.Net&lt;/span&gt;&lt;br /&gt; Dim FileName As String = Server.MapPath("MyFileName.txt")&lt;br /&gt; Response.Clear()&lt;br /&gt; Response.ClearContent()&lt;br /&gt; Response.ContentType = "application/pdf"&lt;br /&gt; Response.AddHeader("Content-Disposition", "attachment; filename=DownloadFile.txt;")&lt;br /&gt;&lt;br /&gt; Dim buffer As Byte() = System.IO.File.ReadAllBytes(FileName)&lt;br /&gt;&lt;br /&gt; Dim mem As New System.IO.MemoryStream()&lt;br /&gt; mem.Write(buffer, 0, buffer.Length)&lt;br /&gt;&lt;br /&gt; mem.WriteTo(Response.OutputStream)&lt;br /&gt; Response.End()&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9197207222512678697-1792950145544937882?l=aspnet-solutions.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspnet-solutions.blogspot.com/feeds/1792950145544937882/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=9197207222512678697&amp;postID=1792950145544937882' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/1792950145544937882'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9197207222512678697/posts/default/1792950145544937882'/><link rel='alternate' type='text/html' href='http://aspnet-solutions.blogspot.com/2008/09/download-file-from-server-to-local.html' title='Download file from the server to local machine'/><author><name>Imrankhan Pathan</name><uri>http://www.blogger.com/profile/00481180443247674321</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
