Wednesday, February 26, 2014

How to find Operating System version using SQL query

There are some cases you wanted to check the Operating system installed on your SQL server. You may not have remote login access to the server where SQL server is installed in that case it will be difficult to know what is the operating system installed on your server where SQL database is installed.

In this article I am going to explain you the simple query which you can run in your SQL server Query analyzer and it will show you the Operating System version installed on your database server.

SQL Server by default provides you an inbuilt table with all the details of the operating system installed on your database server. sys.dm_os_windows_info is the table you may query in this regard.

Your final query will be,

SELECT windows_release, windows_service_pack_level, windows_sku, os_language_version
FROM sys.dm_os_windows_info

And the output of the above query will be,

windows_release windows_service_pack_level windows_sku os_language_version
6.1 Service Pack 1 10 1033

In the above result you can see that windows release is 6.1 means Windows Server 2008 R2 in my case. It can be Windows 7 if your database is not installed on the server.

You can find all the operating system version number in below chart.

Operating system Version number
Windows 8.1 6.3
Windows Server 2012 R2 6.3
Windows 8 6.2
Windows Server 2012 6.2
Windows 7 6.1
Windows Server 2008 R2 6.1
Windows Server 2008 6
Windows Vista 6
Windows Server 2003 R2 5.2
Windows Server 2003 5.2
Windows XP 64-Bit Edition 5.2
Windows XP 5.1
Windows 2000 5

image001

Saturday, February 15, 2014

How to use Timer / Stop Watch using JavaScript

In this article I am going to explain timer/stop watch function using JavaScript. In many situations we may get requirement to show the timer in your application. This article will help you to show the timer using JavaScript in a webpage.

To implement the timer first we will write JavaScript function and save it as .Timer.js.

var milliSec = 0;
var seconds = 0;
var minutes = 0; 
function startTimer()
{   
  var timerVal = document.getElementById('lblTimer');   
  timerVal.value = minutes + ":" + seconds + ":" + milliSec;
  go=setTimeout("startTimer()",1);
  milliSec++;
    if(milliSec==100)
    {
      milliSec=0;
      seconds++;
    }
    if(seconds==60)
    {
      seconds=0;
      minutes++;
  }
}

 function stopTimer()
{
  clearTimeout(go)
}

Below is the HTML code to design the webpage. Here you can see that startTimer() and stopTimer fucntion is called on click of the button. Also you can see that I have referred the Timer.js Javascript file which is saved in the root folder.

<html>
  <head>
  <title>Timer Using JavaScript</title>
  <script type="text/javascript" src="Timer.js"></script>
  </head>
  <body>
    <form>
      <table>
      <tr>
          <td colspan="3" ><input id="lblTimer" type="text" name="displayTime" STYLE="color: red; border:0px; font-family: Verdana; font-weight: bold; font-size: 25px; " size="10" maxlength="30 value="00:00:00" /></td>
      </tr>
      <tr>
          <td>
            <input type="button" value="Start Timer" onclick="startTimer()"/>                   
            <input type="button" value="Stop Timer"  onclick="stopTimer()"/>                   
          </td>            
       </tr>               
       </table>
    </form>
  </body>
</html>

The output looks like below.

StopWatch

Sunday, February 2, 2014

How to list all sub directories in a directory using C#

Do you want to display all directories in the specified directory using C#? Read this article to know how to list the subdirectories using .NET

Here first I added a Label, a TextBox, a Button and a ListBox to the form. Textbox is used to enter the folder path. Once you click on on the button sub directories will be shown in the list box.

We will see the page design first.

image

Below is the source code for the page design.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ListDir.aspx.cs" Inherits="Blog.ListDir" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
        }
        .auto-style2 {
            width: 156px;
        }
        .auto-style3 {
            width: 156px;
            height: 26px;
        }
        .auto-style4 {
            height: 26px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
        <table class="auto-style1">
            <tr>
                <td class="auto-style3">
                    <asp:Label ID="lblDir" runat="server" Text="Enter the Root Directory"></asp:Label>
                </td>
                <td class="auto-style4">
                    <asp:TextBox ID="txtPath" runat="server"></asp:TextBox>
                </td>
                <td class="auto-style4"></td>
            </tr>
            <tr>
                <td class="auto-style2">&nbsp;</td>
                <td>
                    <asp:Button ID="btnDisplay" runat="server" Text="Show All Sub Directories" OnClick="btnDisplay_Click" />
                </td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td class="auto-style2">
                    &nbsp;</td>
                <td>
                    <asp:ListBox ID="lstDir" runat="server" Height="124px" Rows="5" Width="154px"></asp:ListBox>
                </td>
                <td>&nbsp;</td>
            </tr>
        </table>
    </form>
</body>
</html>

On Button Click event write the following code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace Blog
{
    public partial class ListDir : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lstDir.Visible = false;
        }

        protected void btnDisplay_Click(object sender, EventArgs e)
        {
            lstDir.Visible = true;
            lstDir.Items.Clear();
            string strFolderPath = txtPath.Text;
            DirectoryInfo dirInfo = new DirectoryInfo(strFolderPath);
            if (dirInfo.Exists)
            {
                DirectoryInfo[] dirSubDir = dirInfo.GetDirectories();
                for (int i = 0; i < dirSubDir.Length; i++)
                {
                    lstDir.Items.Add(dirSubDir[i].ToString());
                }
            }
            else
            {
                lstDir.Items.Add("No such directory...");
            }
        }
    }
}

And the final output will be like below,

image