Pages

Friday, August 16, 2013

How to Convert Text into MD5 Hash in Asp.net

This article will be explain how to convert a string to an MD5 Hash form. To convert string in MD5 hash form in Asp.net you have to use two namespace  'System.Text'  and  'System.Security.Cryptography'. Here is the complete code for convert simple sting in MD5 form.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string val = ConvertToMD5HASH(TextBox1.Text);
        Response.Write(val);
    }

    public string ConvertToMD5HASH(string text)
    {
        MD5 Secur = System.Security.Cryptography.MD5.Create();
        byte[] ByteText = System.Text.Encoding.ASCII.GetBytes(text);
        byte[] MdHash = Secur.ComputeHash(ByteText);

        StringBuilder Str = new StringBuilder();
        for (int i = 0; i < MdHash.Length; i++)
        {
            Str.Append(MdHash[i].ToString("X2"));
        }
        return Str.ToString();
    }

}

Wednesday, August 7, 2013

How to Calculate Age in Asp.net

This article will be explain how to create Age calculator in Asp.net using c#. To calculate age using following code you have to enter your date of birth in textbox in dd//mm//yyyy format.
Here is Default.aspx page code
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
        <asp:TextBox ID="txtMonth" runat="server" style="top: 249px; left: 412px; position: absolute; height: 22px; width: 200px"></asp:TextBox>
        <asp:TextBox ID="txtYear" runat="server" style="top: 298px; left: 411px; position: absolute; height: 22px; width: 200px"></asp:TextBox>
        <p>
            <asp:TextBox ID="txtDay" runat="server" style="top: 200px; left: 413px; position: absolute; height: 22px; width: 200px"></asp:TextBox>
        </p>
        <asp:Button ID="FindAge" runat="server" style="top: 345px; left: 544px; position: absolute; height: 26px; width: 80px" Text="Find Age" OnClick="FindAge_Click" />
        <asp:Label ID="Result" runat="server" style="top: 428px; left: 387px; position: absolute; height: 19px; width: 321px" ForeColor="Red"></asp:Label>
        <asp:Label ID="Label1" runat="server" style="top: 207px; left: 346px; position: absolute; height: 21px; width: 60px" Text="Day"></asp:Label>
      
        <asp:Label ID="Label2" runat="server" style="top: 256px; left: 346px; position: absolute; height: 19px; width: 55px" Text="Month"></asp:Label>
        <asp:Label ID="Label3" runat="server" style="top: 306px; left: 349px; position: absolute; width: 49px" Text="Year"></asp:Label>
        <asp:Label ID="header" runat="server" style="top: 139px; left: 413px; position: absolute; height: 19px; width: 186px" Text="Enter your Dob"></asp:Label>
      
    </form>
</body>
Here is Default.aspx.cs page code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      
    }
    protected void FindAge_Click(object sender, EventArgs e)
    {
        int year, month, day;
        year = Convert.ToInt32(txtYear.Text);
        month = Convert.ToInt32(txtMonth.Text);
        day = Convert.ToInt32(txtDay.Text);
        DateTime dateTime = new DateTime(year, month, day);
        DateTime td = DateTime.Now;
        int leapYear = 0;
        for (int i = dateTime.Year; i < td.Year; i++)
        {
            if (DateTime.IsLeapYear(i))
            {
                ++leapYear;
            }
        }
        TimeSpan timespan = td.Subtract(dateTime);
        day = timespan.Days - leapYear;
        int intResult = 0;
        year = Math.DivRem(day, 365, out intResult);
        month = Math.DivRem(intResult, 30, out intResult);
        day = intResult;
        Result.Text = "Your Age is" + year.ToString() + " Year/s " + month + " Month/s " + day + " Day/s";
    }

}

Sunday, August 4, 2013

How Install .Net Framework 3.5 Feature in Windows 8

Introduction
In Windows 8 when you try to install an old application then you have a problem and a message such as "An app on your PC needs the following Windows feature" ".Net Framework 3.5 (Includes 3.0 and 2.0)" is displayed and the application doesn't install. This type of problem exists because the application that you try to install requires a .Net Framework 3.5 feature. In Windows 8 .Net Framework 3.5 is disabled by default. When you install Windows 8, .Net Framework 3.5 is not installed automatically, only the .Net Framework 4.5 Advanced Features are installed automatically. If you want to enable .Net Framework 3.5 then you must manually install .Net 3.5 in Windows 8. There are two ways to install .Net Framework 3.5. The first is online and the second is offline.
This article will explain how to install .Net Feature 3.5 in Windows 8 offline. To install .Net Framework 3.5 offline you need a bootable media, such as a Windows 8 DVD, Windows 8 bootable pen drive etc.
How to install .Net Framework 3.5 in Windows 8 offline
Step 1
Insert the bootable media in the computer. bootable media such as windows 8 DVD Disk or bootable windows 8 Pen Drive and then go to the search box and type "CMD" and from the results window open the command prompt as Administrator.
Step 2
In the command prompt go to the root directory. Do that by typing "cd /" then hit Enter.
Command-Prompt-Windows8.jpg
Step 3
Now type the following command into the command prompt. Here "Source:F" is the bootable media, such as a Windows 8 CD drive, Bootable Pen drive etc. "Source:F" might be "Source:D" or "Source:E" depending on the name of the drive.
Dism /online /enable-feature /featurename:NetFx3 /All /Source:F:\sources\sxs /LimitAccess
DISM-Command-Windows8.jpg
Step 4
After typing the command and pressing Enter, wait a while. After installing .Net 3.5 you will get this message:
Installed-Feature-3.5-Windows8.jpg
Step 5
Now restart your computer and try to install the old software.