Wednesday, 26 March 2014

Excel download Number format Issue - Solution

   Response.ContentType = "application/vnd.ms-excel";
                Response.AppendHeader("content-disposition", "attachment; filename=TestFile-"+DateTime.Now.ToFileTime()+".xls");
                string style = @"<style> td { mso-number-format:""0""; } </style> ";// this is used to ensure that the big phone numbers are not converted to exponential values
                Response.Write(style);// apply style
                Response.Write(sw.ToString());
                Response.End();

Monday, 24 March 2014

Server side validation for DATE format dd/mm/yyyy

DateTime.Parse(strinput);
            string[] arr = strinput.Split('/');
            string strNewDate = arr[1] + "/" + arr[0] + "/" + arr[2];

            string strRegex = @"^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$"; // dd/mm/yyyy
            //@"^([0]\d|[1][0-2])\/([0-2]\d|[3][0-1])\/([2][01]|[1][6-9])\d{2}(\s([0-1]\d|[2][0-3])(\:[0-5]\d){1,2})?$"; // MM/dd/yyyy

            Regex re = new Regex(strRegex);

            if (re.IsMatch(strNewDate))
                return (true);
            else
                return (false);

Thursday, 20 March 2014

Share Social Media--Hanmant

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="js/jquery-1.9.1.js"></script>

    <script language="javascript" type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
    <script language="javascript" type="text/javascript" src="https://apis.google.com/js/client:plusone.js"></script>
    <script language="javascript" type="text/javascript">

        function getplusone(url) {
            alert("googleplusones" + url);
            var plusones;
            var params = {
                nolog: true,
                id: url,
                source: "widget",
                userId: "@viewer",
                groupId: "@self"
            };

            gapi.client.setApiKey('AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ')
            gapi.client.rpcRequest('pos.plusones.get', 'v1', params).execute(function (resp) {
                //console.log('count:', resp.result.metadata.globalCounts.count)
                plusones = resp.result.metadata.globalCounts.count;
                alert("google" + plusones)
                $('#lblgoogle').append('+1 ' + plusones);
            });

        }
   
    function getfbcount(url) {
        //alert("facebook" + url);
        var fblikes;
        $.getJSON('http://graph.facebook.com/?id=' + url, function (data) {
            //fblikes = data[url].shares;
            fblikes = data.shares;
            $('#lblFB').append('fb likes ' + fblikes);
            });
    }


    function gettwcount(url) {       
        var tweets;
        $.getJSON('http://urls.api.twitter.com/1/urls/count.json?url=' + url + '&callback=?', function (data) {
            tweets = data.count;
            $('#lblTw').append('tweets ' + tweets);
        });
    }

      

    function getplusone11(url) {
        alert("googleplusones" + url);
        var plusones;
        $.getJSON('https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ' + 'callback=?',
        {
        "method": "pos.plusones.get",
        "id": "p",
        "params": {
        "nolog": true,
        "id": url,
        "source": "widget",
        "userId": "@viewer",
        "groupId": "@self"
        },
        "jsonrpc": "2.0",
        "key": "p",
        "apiVersion": "v1"
    },
    function (data) {
        plusones = data.count;
        alert("google" + plusones)
        $('#lblgoogle').append('+1 ' + plusones);
    });
    }


$(document).ready(function () {
    $('#fbShare').attr('href', 'http://www.facebook.com/sharer.php?u=' + location.href + '&t=' + document.title);
    $('#TwitterLink').attr('href', 'http://twitter.com/share?text=' + document.title + ' ' + document.getElementById('<%=Label1.ClientID%>').innerHTML);
    $('#LinkedInLink').attr('href', 'http://www.linkedin.com/shareArticle?mini=true&url=' + location.href + '&title=' + document.title + '&summary=' + document.title + ' ' + escape(location.href));
    $('#ShareGoogle').attr('href', 'https://plusone.google.com/_/+1/confirm?hl=en&url=' + location.href);

    //var path = window.location.pathname;
    //alert("window.location.pathname : " + path);

    //var href = window.location.href;
    //alert("window.location.href : " + href);

    //var hash = window.location.hash;
    //alert("window.location.hash : " + hash);

    var url = $(location).attr('href');
    //alert("Current URL Using JQuery : " + url);

    getfbcount('http://www.yahoo.com/');
    gettwcount('http://www.yahoo.com/');
   // getplusone('http://www.yahoo.com/');
    getplusone11('http://www.yahoo.com/');

  
});
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" ForeColor="White"></asp:Label>
        <nav class="share">
            <p class="blueBgTitle">Share</p>
                <ul class="shaerMediaIcon">
                    <li class="shaerFacebook"><a id="fbShare" href="javascript:;" target="_blank"><img src="/images/facebook_32.png" alt="facebook" /></a></li>
                    <li class="shaerShapeBox"><asp:Label ID="lblFB" runat="server"></asp:Label></li>
                    <li class="gryeeVLine"></li>
                    <li class="shaerTwitter"><a id="TwitterLink" href="javascript:;"  target="_blank"><img src="/images/twitter_32.png" alt="twitter" /></a></li>
                    <li class="shaerShapeBox"><asp:Label ID="lblTw" runat="server"></asp:Label></li>
                    <li class="gryeeVLine"></li>
                    <li class="shaerIn"><a id="LinkedInLink" href="javascript:;" target="_blank"><img src="/images/linkedin_32.png" alt="linkedin" /></a></li>
                    <li class="shaerShapeBox"><asp:Label ID="lblLNK" runat="server"></asp:Label></li>

                    <li class="gryeeVLine"></li>
   
                    <li class="shaerGooglePlus"><a id="ShareGoogle" runat="server"  target="_blank"><img src="/images/google.png" alt="google" /></a></li>
                    <li class="shaerShapeBox"><asp:Label ID="lblgoogle" runat="server"></asp:Label></li>
                </ul>
                <div class="clear"></div>
                <div class="shareMore">
                        <!-- AddToAny BEGIN -->
                        <a class="a2a_dd" href="http://www.addtoany.com/share_save">More +</a>
                        <script type="text/javascript" src="http://static.addtoany.com/menu/page.js"></script>
                        <!-- AddToAny END -->
                </div>
            </nav>
    </div>
    </form>
</body>
</html>

Tuesday, 11 March 2014

One xsl and multipale xml read , direct xml read in xsl

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.Net;
using System.IO;
using System.Xml;
using System.Xml.Linq;

public partial class xmlxsl : System.Web.UI.UserControl
{
    public string xmlfile = "";
    public string xslfile = "";
    public string xslxmlfile = "";
    public string xslxmltxt = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        string myXmlFile = Server.MapPath(xmlfile);
        XPathDocument myXPathDoc = new XPathDocument(myXmlFile);
        XslCompiledTransform myXslTrans = new XslCompiledTransform();
        string myStyleSheet = Server.MapPath(xslfile);
        XsltSettings xs = new XsltSettings(true, true);
        XmlUrlResolver xur = new XmlUrlResolver();
        myXslTrans.Load(myStyleSheet, xs, xur);

        myXslTrans.Transform(myXmlFile, Server.MapPath(xslxmlfile));
        string strHTML = GetHTML(Server.MapPath(xslxmlfile)); ;
        strHTML = strHTML.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "");
        divHTML.InnerHtml = strHTML;


    }
    public string GetHTML(string strURL)
    {
        string strResult = string.Empty;
        try
        {
            WebResponse objResponse;
            WebRequest objRequest = HttpWebRequest.Create(strURL);
            objResponse = objRequest.GetResponse();
            using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
            {
                strResult = sr.ReadToEnd();
                sr.Close();
            }
        }
        catch (Exception ex)
        {
            // Response.Write(ex.ToString());
        }
        return strResult;
    }
}

-----------------------------------xsl--------------------------------
<?xml version="1.0" encoding='utf-8'?>
<xsl:stylesheet xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html"/>
  <xsl:template match="/">
    <html>
      <head>
        <title> XSLT with XML included </title>
      </head>
      <body style="background-color:lightblue;color:green">
        <table cellSpacing="0" border="1" cellPadding="2">
          <!-- Set Variables -->
          <xsl:variable name="external">
            <xsl:copy-of select="/test/child2.xml"/>
          </xsl:variable>
          <!-- Process Data Start -->
          <xsl:for-each select="//UK_Products_Pipeline/LastFinishCode">
            <tr>
              <xsl:if test="SiteName ='MWB'">
                <td>
                  <xsl:value-of select="SiteName"/>
                </td>
                <td>
                  <xsl:value-of select="LastFinishCode"/>
                </td>
                <td>
                  <xsl:value-of select="Numbers"/>
                </td>
              </xsl:if>
            </tr>
          </xsl:for-each>
          <!-- Process File Data Start -->
          <xsl:call-template name="ExternalData">
         
            <xsl:with-param name="data" select="$external"/>
          </xsl:call-template>
        </table>
      </body>
    </html>
  </xsl:template>
  <xsl:template name="ExternalData">
 
    <xsl:param name="data"/>
   
    <xsl:variable name="external">
      <xsl:copy-of select="/test/child1.xml"/>
    </xsl:variable>
    <table cellSpacing="0" border="1" cellPadding="2" style="background-color:white;color:black">
      <tr>
        <td colspan="3" align="center">
          I do see this.
        </td>
      </tr>
      <!-- Process External Data -->
     
      <xsl:for-each select="document('http://localhost:2115/Xml_transform_xslt/test/child2.xml')//UK_Products_Pipeline/LastFinishCode">
        <tr>
          <td colspan="3" align="center">
            <xsl:value-of select="SiteName"/>
          </td>
        </tr>
        <tr>
          <xsl:if test="SiteName ='UK'">
            <td>
              <xsl:value-of select="SiteName"/>
            </td>
            <td>
              <xsl:value-of select="LastFinishCode"/>
            </td>
            <td>
              <xsl:value-of select="Numbers"/>
            </td>
          </xsl:if>
        </tr>
      </xsl:for-each>
    
    </table>
  </xsl:template>
</xsl:stylesheet>
-------------------xml 1----------
<?xml version="1.0" encoding="utf-8"?>
<UK_Products_Pipeline>
  <LastFinishCode>
    <SiteName>UK</SiteName>
    <LastFinishCode>Agent Logout</LastFinishCode>
    <Numbers>1</Numbers>
  </LastFinishCode>
  <LastFinishCode>
    <SiteName>UK</SiteName>
    <LastFinishCode>Busy</LastFinishCode>
    <Numbers>1</Numbers>
  </LastFinishCode>
  <LastFinishCode>
    <SiteName>UK</SiteName>
    <LastFinishCode>BW Sale</LastFinishCode>
    <Numbers>1 koli</Numbers>
  </LastFinishCode>
</UK_Products_Pipeline>
------------------xml 2-----------------
<?xml version="1.0" encoding="utf-8"?>

<UK_Products_Pipeline>
  <LastFinishCode>
    <SiteName>MWB pramodhanmant</SiteName>
    <LastFinishCode>Bearer Capability Not Presently Authorized (ISDN Cause Code 57)</LastFinishCode>
    <Numbers>1 hanmant</Numbers>
  </LastFinishCode>
  <LastFinishCode>
    <SiteName>MWB</SiteName>
    <LastFinishCode>Confirmed Booking</LastFinishCode>
    <Numbers>1 hanmant</Numbers>
  </LastFinishCode>
  <LastFinishCode>
    <SiteName>MWB</SiteName>
    <LastFinishCode>Lost</LastFinishCode>
    <Numbers>1 hanmant</Numbers>
  </LastFinishCode>
</UK_Products_Pipeline>