Tuesday, 29 October 2013

Jquery bind server side in cs pages

 System.Text.StringBuilder strScriptFB = new System.Text.StringBuilder();
        strScriptFB.Append("<script type=\"text/javascript\">");
        strScriptFB.Append("$(document).ready(function () {");
        strScriptFB.Append("jQuery.getScript('http://connect.facebook.net/en_US/all.js', function () { });");

        strScriptFB.Append("$('#divFBLike').append('<div id=\"fb-root\"></div>');");
        strScriptFB.Append("$('#divFBLike').append('<div class=\"fb-like\" data-href=\"" + strFacebookHTTP + "/idfc-tv-playing.aspx?Vid=" + SessionManager.intVideosID.ToString() + "&fbvidID1234=" + SessionManager.intVideosID.ToString() + "&isValid=1\"data-send=\"false\" data-width=\"210\" height=\"300\" data-show-faces=\"false\"></div><p>&nbsp;</p>');");
        strScriptFB.Append("$('#facebookHolder').append('<fb:comments href=\"" + strFacebookHTTP + "/idfc-tv-playing.aspx?Vid=" + SessionManager.intVideosID + "&fbvID23=" + SessionManager.intVideosID.ToString() + "&isValid=1\" num_posts=\"2\" width=\"213\"></fb:comments>'); ");
        strScriptFB.Append("}); </script>");

        ScriptManager.RegisterClientScriptBlock(this.Page, GetType(), "alert1", strScriptFB.ToString(), false);

Wednesday, 16 October 2013

Bind Dropdown use xml, Dropdown fill by xml

  DataSet  ds= new DataSet();
        ds.ReadXml(Server.MapPath("BindXMLToDropDown.xml"));

        DropDownList1.DataSource = ds;
        DropDownList1.DataTextField = "category";
        DropDownList1.DataValueField = "lastUpdated";
        DropDownList1.DataBind();

Friday, 11 October 2013

Save live image in c sharp

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
 -----------------------------------------
 protected void Button1_Click(object sender, EventArgs e)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(TextBox1.Text.Trim());
        string filname = TextBox1.Text.Trim();
        filname = string.Format("{0:MMMMyyyyHHmmssFFFF}", DateTime.Now) + filname.Substring(filname.LastIndexOf("/") + 1);

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        if ((response.StatusCode == HttpStatusCode.OK ||
                   response.StatusCode == HttpStatusCode.Moved ||
                   response.StatusCode == HttpStatusCode.Redirect) &&
                   response.ContentType.StartsWith("image", StringComparison.OrdinalIgnoreCase))
        {
            using (Stream inputStream = response.GetResponseStream())
            using (Stream outputStream = File.Create(Server.MapPath("images") + "\\" + filname + ""))
            {
                byte[] buffer = new byte[4096];
                int bytesRead;
                do
                {
                    bytesRead = inputStream.Read(buffer, 0, buffer.Length);
                    outputStream.Write(buffer, 0, bytesRead);
                } while (bytesRead != 0);
            }
        }
    }

Sum one by one ,Second highest salary

select a.Id, a.Name, sum(b.Name) as sum from Table_5 a cross join Table_5 b where b.Id <= a.Id group by a.Id, a.Name



Select * From Table_5 T1 Where 3=(Select Count(Distinct(t2.salary)) From Table_5 T2 Where T2.salary > T1.salary)



select min(name) from Table_5 where name in (select   distinct top 5 name  from Table_5 order by name desc)

Wednesday, 9 October 2013

404 error file not found and directory HttpError throw handle

  <httpErrors existingResponse="Replace" errorMode="Custom">

      <remove statusCode="404" subStatusCode="-1" />
      <!--<error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="/errorp.aspx" responseMode="Redirect" />-->
      <error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="/errorpage.aspx" responseMode="ExecuteURL" />
      <error statusCode="400" path="/" responseMode="ExecuteURL" />

    </httpErrors>

  </system.webServer>

Thursday, 26 September 2013

How Auto poastbak in ie 10 Enternet exploer 10 in .net

private void Page_Init(object sender, EventArgs e)
    {
        Page.ClientTarget = "uplevel";
    }

Wednesday, 25 September 2013

Url Rewite

protected void Application_BeginRequest(Object sender, EventArgs e)
    {

 if (HttpContext.Current.Request.QueryString["isValid"] == null)
                {
                    if (HttpContext.Current.Request.UrlReferrer == null && HttpContext.Current.Request.QueryString.Count > 0 && !(HttpContext.Current.Request.Url.ToString().ToLower().Contains("fundpage.aspx")))
                    {
                        if (!HttpContext.Current.Request.Url.ToString().Contains("?2") && !HttpContext.Current.Request.Url.ToString().ToLower().Contains("?formcentre"))
                        {
                            Response.Redirect("~/errorpage.aspx");
                        }

                    }
                    else
                    {
                        // BusinessLogic.URLRewriter.ProcessRequest();
                        URLRewriterNew.URLRewriterNew.ProcessRequest();
                        URLTagRewriter.ProcessRequest();
                    }
                }
                else if (HttpContext.Current.Request.UrlReferrer == null)
                {
                    //Response.Redirect("~/default.aspx");
                }
}


=========================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Web;
using System.Data.SqlClient;
using System.Data;

using System.Xml;

public class URLTagRewriter : IConfigurationSectionHandler
{

    #region Private Variables
    // static AccessData _accessData = new AccessData();
    #endregion
    public static void ProcessRequest()
    {

        //string zSubst = oRewriter.GetSubstitution(HttpContext.Current.Request.Path);

        //Added by Deepak T to check the keyword

        if (HttpContext.Current.Request.Path.ToLower().Contains("aspx"))
        {
            //do nothing
            string zSubst = string.Empty;
            if (HttpContext.Current.Request.Url.AbsoluteUri.ToString().ToLower().Contains("?ptagid="))
            {
                string strPid = HttpContext.Current.Request.QueryString["ptagid"].ToString();
                int id = int.Parse(strPid);
                zSubst = ReadURLFromSql(id.ToString());
                if (zSubst.Length > 0)
                {
                    if (HttpContext.Current.Request.RequestType != "POST")
                    {
                        HttpContext.Current.Response.Redirect(zSubst);
                        //HttpContext.Current.RewritePath(zSubst);
                    }
                }

            }
            else
            {
                //HttpContext.Current.Response.Redirect("~/default.aspx");
            }

        }
        else if (HttpContext.Current.Request.Path.ToLower().Contains("."))
        {
            //do nothing
        }
        else
        {
            string zSubst = string.Empty;
            string strPid ="";
            zSubst = ReadURLFromSql();//ReadXML(HttpContext.Current.Server.MapPath("~/URL.xml"));

            if (zSubst.Length > 0)
            {
                HttpContext.Current.RewritePath(zSubst);
            }
            else
            {
                //HttpContext.Current.Response.Redirect("~/default.aspx");
                // throw new Exception("Page not found");
            }
        }
    }

    public static string ReadURLFromSql()
    {
        string strRequestPath = string.Empty;
        string dbPath = string.Empty;
        string strMatchPath = string.Empty;
        strRequestPath = HttpContext.Current.Request.Path; // got the requested path
        strMatchPath = strRequestPath.Substring(strRequestPath.LastIndexOf("/"), strRequestPath.Length - (strRequestPath.LastIndexOf("/")));
        if (strMatchPath.Contains("/"))
        {
            strMatchPath = strMatchPath.Remove(strMatchPath.IndexOf("/"), 1);
        }

        if (strMatchPath.Contains("'"))
        {
            int index = strMatchPath.IndexOf("'");
            index = index + 1;
            strMatchPath = strMatchPath.Insert(index, "'");
        }
        else
        {
            // strMatchPath = "7";
        }


        DataSet dsURL = new DataSet();


        //dsURL = GetFundPageLink("GetFundPageIDByLink","", strMatchPath);




        //if (dsURL != null && dsURL.Tables.Count > 0 && dsURL.Tables[0].Rows.Count > 0)
        //{
        //    dbPath = dsURL.Tables[0].Rows[0]["ID"].ToString();
      //  string strPid = HttpContext.Current.Request.QueryString["tagid"].ToString();
       //}
        //else
        //{
        //    dbPath = "";
        //}
  
        if (strMatchPath == "equity-funds")
        {
            dbPath = "1";
        }
        else if (strMatchPath == "debt-funds")
        {
            dbPath = "2";
        }
        else if (strMatchPath == "hybrid-funds")
        {
            dbPath = "3";
        }
        else if (strMatchPath == "tax-saving-funds")
        {
            dbPath = "7";
        }
        else if (strMatchPath == "long-term-funds")
        {
            dbPath = "18";
        } else
        {
            dbPath = "";
        }

        string str = string.Empty;
        if (dbPath != "")
            str = "~/mutual-funds-at-a-glance.aspx?tagID=" + dbPath + "";
        else
            str = "";

        return str;
    }

    public static string ReadURLFromSql(string fundID)
    {
        string strRequestPath = string.Empty;
        string dbPath = string.Empty;
        string strMatchPath = string.Empty;
        strRequestPath = HttpContext.Current.Request.Path; // got the requested path


        DataSet dsURL = new DataSet();

        //dsURL = GetFundPageLink("GetFundPageLink", fundID,"");

        if (fundID == "1")
        {
            dbPath = "equity-funds";
        }
        else if (fundID == "2")
        {
            dbPath = "debt-funds";
        }
        else if (fundID == "3")
        {
            dbPath = "hybrid-funds";
        }
        else if (fundID == "7")
        {
            dbPath = "tax-saving-funds";
        }
         else if (fundID == "18")
        {
            dbPath = "long-term-funds";
        }


        //if (dsURL!=null && dsURL.Tables.Count>0 &&  dsURL.Tables[0].Rows.Count > 0)
        //{
        //dbPath = "pramod";// dsURL.Tables[0].Rows[0]["FundPageLink"].ToString();
        // }

        string str = string.Empty;
        if (dbPath != "")
            str = "~/" + dbPath;
        else
            str = "";

        return str;
    }


    //public static DataSet GetFundPageLink(string strAction, string strFundID,string strFundLink)
    //{
    //    try
    //    {

    //        _accessData.Section = "FundPageLinks";
    //        object[] obj = _accessData.GetObject();
    //        obj[0] = strAction;
    //        obj[1] = strFundID;
    //        obj[2] = strFundLink;

    //        DataSet _ds = _accessData.getDataSet(obj);
    //        return _ds;
    //    }
    //    catch (Exception ex)
    //    {
    //        throw (ex);
    //    }
    //}



    #region Implementation of IConfigurationSectionHandler
    public object Create(object parent, object configContext, XmlNode section)
    {
        //_oRules = section;

        // TODO: Compile all Regular Expressions

        return this;
    }

    #endregion

}