Pages

Friday 14 March 2014

How to Get All Files from Directory and Sub directories and Display it in Grid view C#

How to Get All Files from Directory and Sub directories and Display it in Grid view C#

C# Code:
 
 protected void BindGridview()
{
string strpath = @"C:\personal\asp.net\";
string[] folders = Directory.GetFiles(strpath, "*", SearchOption.AllDirectories);
gvDetails.DataSource = folders;
gvDetails.DataBind();
}

VB Code:

 Protected Sub BindGridview()
Dim strpath As String = "C:\personal\asp.net\"
Dim folders As String() = Directory.GetFiles(strpath, "*", SearchOption.AllDirectories)
gvDetails.DataSource = folders
gvDetails.DataBind()
End Sub

.Aspx Code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>How to Get All Files from Folder and Subfolders & Display it in Gridview in C#  asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnGetFiles" Text="Get Files From Folder & Sub Folders" runat="server" onclick="btnGetFiles_Click" />
<asp:GridView ID="gvDetails" CellPadding="5" runat="server">
<HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
</asp:GridView>
</div>
</form>
</body>
</html>

C# Code:

using System;
using System.IO;

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

    }
    protected void btnGetFiles_Click(object sender, EventArgs e)
    {
        BindGridview();
    }
    protected void BindGridview()
    {
        string strpath = @"C:\personal\asp.net\";
        string[] folders = Directory.GetFiles(strpath, "*", SearchOption.AllDirectories);
        gvDetails.DataSource = folders;
        gvDetails.DataBind();
    }
}

VB Code:

 Imports System.IO
Partial Class VBCode
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
' insert files in folder
Protected Sub btnGetFiles_Click(ByVal sender As Object, ByVal e As EventArgs)
BindGridview()
End Sub
' Bind Data to Gridview
Protected Sub BindGridview()
Dim strpath As String = "C:\personal\asp.net\"
Dim folders As String() = Directory.GetFiles(strpath, "*", SearchOption.AllDirectories)
gvDetails.DataSource = folders
gvDetails.DataBind()
End Sub
End Class

Demo:

How to Get All Files from Folder and Subfolders & Display it in Gridview in C# asp.net

How to Get All Files from Folder and Subfolders & Display it in Gridview in C# asp.net

C# Code:
 
 protected void BindGridview()
{
string strpath = @"C:\personal\asp.net\";
string[] folders = Directory.GetFiles(strpath, "*", SearchOption.AllDirectories);
gvDetails.DataSource = folders;
gvDetails.DataBind();
}

VB Code:

 Protected Sub BindGridview()
Dim strpath As String = "C:\personal\asp.net\"
Dim folders As String() = Directory.GetFiles(strpath, "*", SearchOption.AllDirectories)
gvDetails.DataSource = folders
gvDetails.DataBind()
End Sub

.Aspx Code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>How to Get All Files from Folder and Subfolders & Display it in Gridview in C#  asp.net</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnGetFiles" Text="Get Files From Folder & Sub Folders" runat="server" onclick="btnGetFiles_Click" />
<asp:GridView ID="gvDetails" CellPadding="5" runat="server">
<HeaderStyle BackColor="#df5015" Font-Bold="true" ForeColor="White" />
</asp:GridView>
</div>
</form>
</body>
</html>

C# Code:

using System;
using System.IO;

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

    }
    protected void btnGetFiles_Click(object sender, EventArgs e)
    {
        BindGridview();
    }
    protected void BindGridview()
    {
        string strpath = @"C:\personal\asp.net\";
        string[] folders = Directory.GetFiles(strpath, "*", SearchOption.AllDirectories);
        gvDetails.DataSource = folders;
        gvDetails.DataBind();
    }
}

VB Code:

 Imports System.IO
Partial Class VBCode
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
' insert files in folder
Protected Sub btnGetFiles_Click(ByVal sender As Object, ByVal e As EventArgs)
BindGridview()
End Sub
' Bind Data to Gridview
Protected Sub BindGridview()
Dim strpath As String = "C:\personal\asp.net\"
Dim folders As String() = Directory.GetFiles(strpath, "*", SearchOption.AllDirectories)
gvDetails.DataSource = folders
gvDetails.DataBind()
End Sub
End Class

Demo:

How to Convert 12 Hour AM/PM Time to 24 Hours Time Format JavaScript

How to Convert 12 Hour AM/PM Time to 24 Hours Time Format JavaScript
 
 <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JavaScript Convert AM/PM to 24 Hours Time</title>
<script type="text/javascript">
function Converttimeformat() {
// var time = $("#starttime").val();
var time = document.getElementById('txttime').value;
var hrs = Number(time.match(/^(\d+)/)[1]);
var mnts = Number(time.match(/:(\d+)/)[1]);
var format = time.match(/\s(.*)$/)[1];
if (format == "PM" && hrs < 12) hrs = hrs + 12;
if (format == "AM" && hrs == 12) hrs = hrs - 12;
var hours = hrs.toString();
var minutes = mnts.toString();
if (hrs < 10) hours = "0" + hours;
if (mnts < 10) minutes = "0" + minutes;
alert(hours + ":" + minutes);
}
</script>
</head>
<body>
<div>
<table>
<tr>
<td><b>Enter Time:</b></td>
<td><input type="text" id="txttime" value="10:00 PM" /></td>
</tr>
<tr>
<td></td>
<td><input type="button" id="btnConvert" value="Convert to AM/PM" onclick="Converttimeformat()" /></td>
</tr>
</table>
</div>
</body>
</html>

Enter Time:


How to Convert AM PM Time to 24 Hour Time jQuery

How to Convert AM PM Time to 24 Hour Time jQuery
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>jQuery Convert AM / PM time to 24 hours time</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#btnConvert').click(function () {
                var time = $("#txttime").val();
                var hrs = Number(time.match(/^(\d+)/)[1]);
                var mnts = Number(time.match(/:(\d+)/)[1]);
                var format = time.match(/\s(.*)$/)[1];
                if (format == "PM" && hrs < 12) hrs = hrs + 12;
                if (format == "AM" && hrs == 12) hrs = hrs - 12;
                var hours = hrs.toString();
                var minutes = mnts.toString();
                if (hrs < 10) hours = "0" + hours;
                if (mnts < 10) minutes = "0" + minutes;
                alert(hours + ":" + minutes);
            })
        })
    </script>
</head>
<body>
    <table>
        <tr>
            <td><b>Enter Time:</b></td>
            <td>
                <input type="text" id="txttime" value="12:00 PM" /></td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" id="btnConvert" value="Convert to AM/PM" /></td>
        </tr>
    </table>
</body>
</html>

Enter Time:


How to Check Given Date Greater than Current Date or Today Date JavaScript JQuery

How to Check Given Date Greater than Current Date or Today Date JavaScript JQuery 
 
 <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>How to Check Given Date Greater than Current Date or Today Date JavaScript JQuery </title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
    $(function () {
        $('#btnConvert').click(function () {
            var param1 = new Date();
            var ddate = $('#txtdate').val();
            var time = $('#txttime').val();
            var hours = Number(time.match(/^(\d+)/)[1]);
            var minutes = Number(time.match(/:(\d+)/)[1]);
            var format = time.match(/\s(.*)$/)[1];
            if (format == "PM" && hours < 12) hours = hours + 12;
            if (format == "AM" && hours == 12) hours = hours - 12;
            var sHours = hours.toString();
            var sMinutes = minutes.toString();
            if (hours < 10) sHours = "0" + sHours;
            if (minutes < 10) sMinutes = "0" + sMinutes;
            ddate = ddate + " " + sHours + ":" + sMinutes + ":00";
            var date1 = new Date(ddate);
            var date2 = new Date();
            if (date1 < date2) {
                alert('Please Enter Date time Greater than Current Date time');
                $('#txtdate').focus();
                return false;
            }
        })
    })
</script>
</head>
<body>
<table>
<tr>
<td><b>Enter Date:</b></td>
<td><input type="text" id="txtdate" value="08/27/2013" /></td>
</tr>
<tr>
<td><b>Enter Time:</b></td>
<td><input type="text" id="txttime" value="10:00 PM" /></td>
</tr>
<tr>
<td></td>
<td><input type="button" id="btnConvert" value="Convert to AM/PM" /></td>
</tr>
</table>
</body>
</html> <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Check Given Date Time Greater than Current Date time in JavaScript</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
    $(function () {
        $('#btnConvert').click(function () {
            var param1 = new Date();
            var ddate = $('#txtdate').val();
            var time = $('#txttime').val();
            var hours = Number(time.match(/^(\d+)/)[1]);
            var minutes = Number(time.match(/:(\d+)/)[1]);
            var format = time.match(/\s(.*)$/)[1];
            if (format == "PM" && hours < 12) hours = hours + 12;
            if (format == "AM" && hours == 12) hours = hours - 12;
            var sHours = hours.toString();
            var sMinutes = minutes.toString();
            if (hours < 10) sHours = "0" + sHours;
            if (minutes < 10) sMinutes = "0" + sMinutes;
            ddate = ddate + " " + sHours + ":" + sMinutes + ":00";
            var date1 = new Date(ddate);
            var date2 = new Date();
            if (date1 < date2) {
                alert('Please Enter Date time Greater than Current Date time');
                $('#txtdate').focus();
                return false;
            }
        })
    })
</script>
</head>
<body>
<table>
<tr>
<td><b>Enter Date:</b></td>
<td><input type="text" id="Text1" value="03/15/2013" /></td>
</tr>
<tr>
<td><b>Enter Time:</b></td>
<td><input type="text" id="Text2" value="10:00 PM" /></td>
</tr>
<tr>
<td></td>
<td><input type="button" id="Button1" value="Convert to AM/PM" /></td>
</tr>
</table>
</body>
</html

Enter Date:
Enter Time:


Saturday 1 March 2014

How To Validate Email with Regular Expression C#

Email Validation with Regular Expression C#

Below is the Regular Expression to Validate Email Address 
 
bool isEmail = Regex.IsMatch(txtEmail.Text.Trim(), @"\A(?:[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)\Z");

Sample Code:

 <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Regular Expression to validate Email Address</title>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td><b>Enter Email:</b></td>
<td>
<asp:TextBox ID="txtEmail" runat="server" />
</td>
</tr>
<tr>
<td></td>
<td><asp:Button ID="btnValidate" runat="server" Text="Validate Email"
onclick="btnValidate_Click" /> </td>
</tr>
</table>
<asp:label id="lblerrormsg" runat="server" style=" font-weight:bold; " />
</form>
</body>
</html>




How To Date Greater than From Date in JavaScript C#

How To Date Greater than From Date in JavaScript C#
 
http://fantasyaspnet.blogspot.in/2013/04/jquery-datepicker-example-or-jquery.html


How To Hide DIV Elements After 5 Seconds or Some Time Delay Using jQuery in C#

How To Hide DIV Elements After 5 Seconds or Some Time Delay Using jQuery in C#
 <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Hide DIV Elements after 10 seconds</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
    $(function () {
        setTimeout(function () { $("#testdiv").fadeOut(1500); }, 5000)
        $('#btnclick').click(function () {
            $('#testdiv').show();
            setTimeout(function () { $("#testdiv").fadeOut(1500); }, 5000)
        })
    })
</script>
<style type="text/css">
.content
{
border: 2px solid Red;
color: #008000;
padding: 10px;
width: 400px;
font-family:Calibri;
font-size:16pt
}
</style>
</head>
<body>
<input type="button" id="btnclick" value="Show DIV" />
<div class="content" id="testdiv" class="">
Hi, Welcome to http://fantasyaspnet.blogspot.com
It will disappear in 5 seconds!
</div>
</body>
</html>



Hi, Welcome to http://fantasyaspnet.blogspot.com It will disappear in 5 seconds!