Tuesday, 8 April 2014

Find Clint IP Address using C#

        string strHostName = "";
        strHostName = System.Net.Dns.GetHostName();
        IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
        IPAddress[] addr = ipEntry.AddressList;
        return addr[addr.Length - 1].ToString();

Find MAC Address using C#

public string GetMACAddress()
    {
        NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
        String sMacAddress = string.Empty;
        foreach (NetworkInterface adapter in nics)
        {
            if (sMacAddress == String.Empty)// only return MAC Address from first card
            {
                //IPInterfaceProperties properties = adapter.GetIPProperties();
                sMacAddress = adapter.GetPhysicalAddress().ToString();
            }
        } return sMacAddress;
    }

Thursday, 3 April 2014

browser close event

 window.onbeforeunload = function(e) {
            // check condition

            return 'Dialog text here.';
        };

Wednesday, 2 April 2014

export html table to csv file

$(document).ready(function() {

    function exportTableToCSV($table, filename) {

        var $rows = $table.find('tr:has(td)'),

        // Temporary delimiter characters unlikely to be typed by keyboard
        // This is to avoid accidentally splitting the actual contents
            tmpColDelim = String.fromCharCode(11), // vertical tab character
            tmpRowDelim = String.fromCharCode(0), // null character

        // actual delimiter characters for CSV format
            colDelim = '","',
            rowDelim = '"\r\n"',

        // Grab text from table into CSV formatted string
            csv = '"' + $rows.map(function(i, row) {
                var $row = $(row),
                    $cols = $row.find('td');

                return $cols.map(function(j, col) {
                    var $col = $(col),
                        text = $col.text();

                    return text.replace('"', '""'); // escape double quotes

                }).get().join(tmpColDelim);

            }).get().join(tmpRowDelim)
                .split(tmpRowDelim).join(rowDelim)
                .split(tmpColDelim).join(colDelim) + '"',

        // Data URI
            csvData = 'data:application/csv;charset=utf-8,' +
             encodeURIComponent(csv);

        $(this)
            .attr({
                'download': filename,
                'href': csvData,
                'target': '_blank'
            });
    }

    // This must be a hyperlink
    $(".export").on('click', function(event) {
        // CSV
        var fileName = $(this).attr('fileName');
        exportTableToCSV.apply(this, [$('#dvData>table'), fileName + '.csv']);

        // IF CSV, don't do event.preventDefault() or return false
        // We actually need this to be a typical hyperlink
    });
});

Read data on web page and export in excel

<script type="text/javascript">

        $(function() {
            if ($('#ctl00_ContentPlaceHolder1_hdnIsPostBack').val() == '1') {
                OpenWordList();
            }
            $('#<%= FileUploadToServer.ClientID %>').on('change', function(e) {
                $('#<%= btnUpload.ClientID%>').trigger('click'); // trigger the btn button click which i have hidden using style='display:none'
            });

            $('#<%= SheKeyFileUploadToServer.ClientID %>').on('change', function(e) {
                $('#<%= tbnSheKeyUpload.ClientID%>').trigger('click'); // trigger the btn button click which i have hidden using style='display:none'
            });

            $('#<%= BenHeKeyFileUploadToServer.ClientID %>').on('change', function(e) {
                $('#<%= btnBenHeKeyUpload.ClientID%>').trigger('click'); // trigger the btn button click which i have hidden using style='display:none'
            });

            $('#<%= BenSheKeyFileUploadToServer.ClientID %>').on('change', function(e) {
                $('#<%= btnBenSheKeyUpload.ClientID%>').trigger('click'); // trigger the btn button click which i have hidden using style='display:none'
            });
        });

        function IsConfirmationExist() {
            var msg = confirm("The entered word is already there in the Blocked Word(s) List and you cannot add it here. \n Do you want to Delete from the Blocked Word(s) List to add here.");
            if (msg == true) {
                $('#ctl00_ContentPlaceHolder1_hdnIsExist').val(1);
            }
            else {
                $('#ctl00_ContentPlaceHolder1_hdnIsExist').val(0);
            }
            $('#<%= btnUpdateImportData.ClientID%>').trigger('click');
        }
        function getFile(FileUploadType) {
            if (FileUploadType == 'He') {
                $('#<%= FileUploadToServer.ClientID%>').click();
            }
            if (FileUploadType == 'She') {
                $('#<%= SheKeyFileUploadToServer.ClientID%>').click();
            }

            if (FileUploadType == 'BenHe') {
                $('#<%= BenHeKeyFileUploadToServer.ClientID%>').click();
            }
            if (FileUploadType == 'BenShe') {
                $('#<%= BenSheKeyFileUploadToServer.ClientID%>').click();
            }
        }

        var tr = '<table id="testTable"><tr><td style="font-size:16px; font-weight:bold; color:blue;" id="PageTitle"></td></tr>';
        function ExportPick_Words_Male(fileName) {
            $('#HEwordlist table td:has(:input[type=text])').each(function() {
                //tr = tr + '<tr><td>' + $(this).find("input").val() + '</td></tr>';
                tr = tr + '<tr><td>' + $(this).find("span").html() + '</td></tr>';
            });
            tr = tr + '</table>';
            $('#tblExportList').empty();
            $('#tblExportList').append(tr);
            $('#PageTitle').html('Pick Words - Male');
            tableToExcel('testTable', fileName)
        }


        function ExportPick_Words_Female(fileName) {
            $('#SHEwordlist table td:has(:input[type=text])').each(function() {
                // tr = tr + '<tr><td>' + $(this).find("input").val() + '</td></tr>';
                tr = tr + '<tr><td>' + $(this).find("span").html() + '</td></tr>';
            });
            tr = tr + '</table>';
            $('#tblExportList').empty();
            $('#tblExportList').append(tr);
            $('#PageTitle').html('Pick Words - Female');
            tableToExcel('testTable', fileName)
        }
        function ExportStop_Words(fileName) {
            $('#HEBlock_wordlist table td:has(:input[type=text])').each(function() {
                tr = tr + '<tr><td>' + $(this).find("span").html() + '</td></tr>';

            });
            tr = tr + '</table>';
            $('#tblExportList').empty();
            $('#tblExportList').append(tr);
            $('#PageTitle').html('Stop Words');
            tableToExcel('testTable', fileName)
        }
        function ExportObscene_Words(fileName) {
            $('#SHEBlock_wordlist table td:has(:input[type=text])').each(function() {
                //tr = tr + '<tr><td>' + $(this).find("input").val() + '</td></tr>';
                tr = tr + '<tr><td>' + $(this).find("span").html() + '</td></tr>';
            });
            tr = tr + '</table>';
            $('#tblExportList').empty();
            $('#tblExportList').append(tr);
            $('#PageTitle').html('Obscene Words');
            tableToExcel('testTable', fileName)
        }

        var tableToExcel = (function() {

            var uri = 'data:application/vnd.ms-excel;base64,'
            , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
            , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
            , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
            return function(table, name) {
                if (!table.nodeType) table = document.getElementById(table)
                var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
                window.location.href = uri + base64(format(template, ctx))
            }
        })()
    </script>

Sunday, 23 March 2014

Export Excel using JQuery

<!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>
    <title></title>
    <!--    <style type="text/css">
        body
        {
            font-size: 12pt;
            font-family: Calibri;
            padding: 10px;
        }
        table
        {
            border: 1px solid black;
        }
        th
        {
            border: 1px solid black;
            padding: 5px;
            background-color: grey;
            color: white;
        }
        td
        {
            border: 1px solid black;
            padding: 5px;
        }
        input
        {
            font-size: 12pt;
            font-family: Calibri;
        }
    </style>-->

    <script type="text/javascript">
        var tableToExcel = (function() {
            var uri = 'data:application/vnd.ms-excel;base64,'
    , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
    , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
    , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
            return function(table, name) {
                if (!table.nodeType) table = document.getElementById(table)
                var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
                window.location.href = uri + base64(format(template, ctx))
            }
        })()
    </script>

</head>
<body>
    <input type="button" onclick="tableToExcel('testTable', 'W3C Example Table')" value="Export to Excel">
    <table id="testTable" summary="Code page support in different versions of MS Windows."
        rules="groups" frame="hsides" border="2">
        <caption>
            Search Results: Funeral Homes</caption>
        <colgroup align="center">
        </colgroup>
        <colgroup align="left">
        </colgroup>
        <colgroup span="2" align="center">
        </colgroup>
        <colgroup span="3" align="center">
        </colgroup>
        <thead valign="top">
            <tr>
                <th>
                    Funeral Home
                </th>
                <th>
                    City
                </th>
                <th>
                    Prov/State
                </th>
                <th>
                    LocCode Group
                </th>
                <th>
                    LocCode Group
                </th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>
                    1200
                </td>
                <td style="background-color: #00f; color: #fff">
                    Unicode (BMP of ISO/IEC-10646)
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                    X
                </td>
                <td>
                    X
                </td>
                <td>
                    *
                </td>
            </tr>
            <tr>
                <td>
                    1250
                </td>
                <td style="font-weight: bold">
                    <a href="http://www.jquery2dotnet.com/">http://www.jquery2dotnet.com/</a>
                </td>
                <td>
                    X
                </td>
                <td>
                </td>
                <td>
                    X
                </td>
                <td>
                    X
                </td>
                <td>
                    X
                </td>
            </tr>
            <tr>
                <td>
                    1251
                </td>
                <td>
                    Windows 3.1 Cyrillic
                </td>
                <td>
                    X
                </td>
                <td>
                </td>
                <td>
                    X
                </td>
                <td>
                    X
                </td>
                <td>
                    X
                </td>
            </tr>
            <tr>
                <td>
                    1252
                </td>
                <td>
                    Windows 3.1 US (ANSI)
                </td>
                <td>
                    X
                </td>
                <td>
                </td>
                <td>
                    X
                </td>
                <td>
                    X
                </td>
                <td>
                    X
                </td>
            </tr>
            <tr>
                <td>
                    1253
                </td>
                <td>
                    Windows 3.1 Greek
                </td>
                <td>
                    X
                </td>
                <td>
                </td>
                <td>
                    X
                </td>
                <td>
                    X
                </td>
                <td>
                    X
                </td>
            </tr>
            <tr>
                <td>
                    1254
                </td>
                <td>
                    Windows 3.1 Turkish
                </td>
                <td>
                    X
                </td>
                <td>
                </td>
                <td>
                    X
                </td>
                <td>
                    X
                </td>
                <td>
                    X
                </td>
            </tr>
            <tr>
                <td>
                    1255
                </td>
                <td>
                    Hebrew
                </td>
                <td>
                    X
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                </td>
                <td>
                    X
                </td>
            </tr>
            <tr>
                <td..

Send Mail using C#


string subject = "Forget Password";
            StringBuilder Bodymsg = new StringBuilder();
         
            string smtpPort = ConfigurationManager.AppSettings.Get("SmtpPort").ToString();
            string smtpUser = ConfigurationManager.AppSettings.Get("smtpUsername").ToString();
            string smtpPassword =ConfigurationManager.AppSettings.Get("smtpPassword").ToString();
            string SmtpAddress = ConfigurationManager.AppSettings.Get("SmtpAddress").ToString();
            bool enablessl = Convert.ToBoolean(ConfigurationManager.AppSettings.Get("enablessl"));
            string toAddress = email;
            Bodymsg.Append("Dear " + name + "</br> Your User Id=" + email + "</br> and Password=" + Password + "</br> Thank </br>" + smtpUser);
            MailMessage mailMessage = new MailMessage(smtpUser, toAddress);
            mailMessage.Subject = subject;
         
            mailMessage.Body = Bodymsg.ToString();
            SmtpClient mailSender = new SmtpClient(SmtpAddress, Convert.ToInt32(smtpPort));
            mailSender.EnableSsl = Convert.ToBoolean(enablessl);
            NetworkCredential myCreds = new NetworkCredential(smtpUser, smtpPassword);
            mailSender.Credentials = myCreds;
            mailMessage.IsBodyHtml = true;
            mailSender.Send(mailMessage);
            return "1";