What are sealed classes and sealed methods


Sealed Class

Sealed class is used to define the inheritance level of a class.
The sealed modifier is used to prevent derivation from a class. An error occurs if a sealed class is specified as the base class of another class.

Generating Random Passwords with ASP. NET and C#

Generating random passwords can increase the security of a website by taking the process out of the hands of the user, or simply providing an alternative, and thus reducing the chance of easily-guessable passwords being used. This tutorial shows a simple method of creating a random password.

Webcam Capture and save clip in Silverlight 4.0 with outofBrowser (o.o.b) Application

In this article, how to capture a frame from a Web Camera using a Silverlight 4.0 Application is described.

Converting Numbers to Words in C#

The program supports both the US and UK numbering systems. For example the number 620 would be expressed as follows:

    Six Hundred Twenty   (in the US system)
    Six Hundred and Twenty  (in the UK system)

Use JSON and JavaScript to create a lightweight GridView

This post is going to show you how to use JSON and JavaScript to create a light weight GridView in JavaScript.
1. converting data in JSON
2. using JavaScript to create GridView
3. applying paging and sorting to it.

Creating Credential Store for Form Authentication in ASP.NET 3.5

When we don't want to use Windows Credentials to validate a user, we can utilize the ASP.NET infrastructure to implement our own authentication infrastructure which includes a custom login page that validates a user against credentials such as a database and later established security context on each request. ASP.NET leverages it's framework to support cookies and establishes the security context for each web request; this is called form authentication.

Implementing the QT Algorithm using C#

Quality Threshold (or QT) is an algorithm used in cluster analysis which is described in this Wikipedia article (http://en.wikipedia.org/wiki/Cluster_analysis).

The basic idea of cluster analysis is to partition a set of points into clusters which have some relationship to each other. In the case of QT the user chooses the maximum diameter (i.e. distance between points) that a cluster can have and each point is then considered in turn, along with its neighbors, and allocated to a cluster.

The source code is listed below in case it is of interest to anyone else involved in this specialized field.

Source code including sample data

System;using System.Collections.Generic;
struct Point{
    public int X, Y;
    public Point(int x, int y)
        this.X = x;
        this.Y = y;
    public override string ToString()
        return String.Format("({0}, {1})", X, Y);

    public static int DistanceSquared(Point p1, Point p2)
        int diffX = p2.X - p1.X;
        int diffY = p2.Y - p1.Y;
        return diffX * diffX + diffY * diffY;
static class QT{
    static void Main()
        List<Point> points = new List<Point>();
        // sample data        points.Add(new Point(0,100));
        points.Add(new Point(0,200));
        points.Add(new Point(0,275));
        points.Add(new Point(100, 150));
        points.Add(new Point(200,100));
        points.Add(new Point(250,200));
        double maxDiameter = 150.0;
        List<List<Point>> clusters = GetClusters(points, maxDiameter);
         // print points to console        Console.WriteLine("The {0} points are :\n", points.Count);
        foreach(Point p in points) Console.Write(" {0} ", p);
        // print clusters to console         for(int i = 0; i < clusters.Count; i++)
           int count = clusters[i].Count;
           string plural = (count != 1) ? "s" : "";
           Console.WriteLine("\nCluster {0} consists of the following {1} point{2} :\n", i + 1, count, plural);
           foreach(Point p in clusters[i]) Console.Write(" {0} ", p);
    static List<List<Point>> GetClusters(List<Point> points, double maxDiameter)
        if (points == null) return null;
        points = new List<Point>(points); // leave original List unaltered         List<List<Point>> clusters = new List<List<Point>>();
        while (points.Count > 0)
            List<Point> bestCandidate = GetBestCandidate(points, maxDiameter);

        return clusters;
    /*         GetBestCandidate() returns first candidate cluster encountered if there is more than one
        with the maximum number of points.
    static List<Point> GetBestCandidate(List<Point> points, double maxDiameter)
        double maxDiameterSquared = maxDiameter * maxDiameter; // square maximum diameter                List<List<Point>> candidates = new List<List<Point>>(); // stores all candidate clusters        List<Point> currentCandidate = null; // stores current candidate cluster        int[] candidateNumbers = new int[points.Count]; // keeps track of candidate numbers to which points have been allocated        int totalPointsAllocated = 0; // total number of points already allocated to candidates        int currentCandidateNumber = 0; // current candidate number
        for(int i = 0; i < points.Count; i++)
            if (totalPointsAllocated == points.Count) break; // no need to continue further             if (candidateNumbers[i] > 0) continue; // point already allocated to a candidate            currentCandidateNumber++;
            currentCandidate = new List<Point>(); // create a new candidate cluster            currentCandidate.Add(points[i]); // add the current point to it            candidateNumbers[i] = currentCandidateNumber;
            Point latestPoint = points[i]; // latest point added to current cluster            int[] diametersSquared = new int[points.Count]; // diameters squared of each point when added to current cluster
            // iterate through any remaining points            // successively selecting the point closest to the group until the threshold is exceeded            while (true)
                if (totalPointsAllocated == points.Count) break; // no need to continue further                                int closest = -1; // index of closest point to current candidate cluster                int minDiameterSquared = Int32.MaxValue; // minimum diameter squared, initialized to impossible value 
                for (int j = i + 1; j < points.Count; j++)
                   if(candidateNumbers[j] > 0) continue; // point already allocated to a candidate           
                   // update diameters squared to allow for latest point added to current cluster                    int distSquared  = Point.DistanceSquared(latestPoint, points[j]);
                   if (distSquared > diametersSquared[j]) diametersSquared[j] = distSquared;
                   // check if closer than previous closest point                   if (diametersSquared[j] < minDiameterSquared)
                       minDiameterSquared = diametersSquared[j];
                       closest = j;

                // if closest point is within maxDiameter, add it to the current candidate and mark it accordingly                if ((double)minDiameterSquared <= maxDiameterSquared)
                   candidateNumbers[closest] = currentCandidateNumber;
                else // otherwise finished with current candidate                {
            // add current candidate to candidates list            candidates.Add(currentCandidate);
        // now find the candidate cluster with the largest number of points        int maxPoints = -1; // impossibly small value        int bestCandidateNumber = 0; // ditto        for(int i = 0; i < candidates.Count; i++)
           if (candidates[i].Count > maxPoints)
               maxPoints = candidates[i].Count;
               bestCandidateNumber = i + 1; // counting from 1 rather than 0           }
        // iterating backwards to avoid indexing problems, remove points in best candidate from points list        // this will automatically be persisted to caller as List<Point> is a reference type        for(int i = candidateNumbers.Length - 1; i >= 0; i--)
            if (candidateNumbers[i] == bestCandidateNumber) points.RemoveAt(i);

        // return best candidate to caller                        return candidates[bestCandidateNumber - 1];


File Transfer Program using C#.Net Windows Application

How to easily send files (including Audio, Video, doc or any type of file) from Client to Server. System.Net.Sockets;using System.IO;

Then write code for the button1 (Browse) and the button2 (Send) as in the following.

For example:

using System;

Select Single Radio Button in Gridview in Asp.Net

In this article we will learn how to select only one row of a GridView using RadioButtons whereas normally a RadioButton does not support selection of only one RadioButton within a row.


In ASP.Net the GridView control does not support selection of a single RadioButton that works as a group across rows. Generally as you know a RadioButton is a control that works in a group for selecting only one option. If we take RadioButtonList control it will work everywhere, which applies to a GridView also but if we use only one RadioButton control for each row in GridView it will not allow us to select only one. Try selecting a RadioButton in every row; it will allow selection of multiple rows in GridView. Here we will see how to restrict the user to select only one RadioButton within a GridView control.

For doing this task need to write some Javascript function. We will step by step follow.

Step 1:

Start new website. Put the GridView control on the Default.aspx page with RadioButton control in TemplateField like bellow.

ID="GridView1" runat="server" AutoGenerateColumns="False"
            DataKeyNames="AuthId">            <Columns>            <asp:TemplateField ShowHeader="false">            <ItemTemplate>            <asp:RadioButton ID="rdbauthid" runat="server" onclick="javascript:CheckOtherIsCheckedByGVID(this);" />            </ItemTemplate>            </asp:TemplateField>            <asp:BoundField HeaderText="AUTHOR NAME" DataField="AuthName" />            <asp:BoundField HeaderText="AUTHOR LOCATION" DataField="AuthLocation" />            </Columns>

In the above you may see that in the Click event of the RadioButton control I call a Javascript function.

Step 2:

Write the script as below for checking the current selection of the RadioButton control; if more than one is selected then the other selection is removed. Other than this there are two more methods to do same task.
<script type="text/javascript">            function CheckOtherIsCheckedByGVID(spanChk) {
                var IsChecked = spanChk.checked;
                if (IsChecked) {
                    spanChk.parentElement.parentElement.style.backgroundColor = '#228b22';
                    spanChk.parentElement.parentElement.style.color = 'white';
                var CurrentRdbID = spanChk.id;
                var Chk = spanChk;
                Parent = document.getElementById("<%=GridView1.ClientID%>");
                var items = Parent.getElementsByTagName('input');
                for (i = 0; i < items.length; i++) {
                    if (items[i].id != CurrentRdbID && items[i].type == "radio") {
                        if (items[i].checked) {
                            items[i].checked = false;
                            items[i].parentElement.parentElement.style.backgroundColor = 'white'
                            items[i].parentElement.parentElement.style.color = 'black';


Verify Email Online

We had a database of hundreds of emails which were collected over years. The problem here is that some of the email exists, some do not. So while sending notifications to clients, the retuned invalid user mail messages require a lot of manual work to clear them. Our idea is to verify whether an email exists before sending the mail. Everything should be automatic and less time consuming.

E-card generator using ASP.NET 3.5

Let us generate a simple e-card generator using ASP.NET 3.5. In this we are dividing the web page region into two half on the left there is an ordinary <div> tag containing a set of web controls for specifying card option and on right is a panel control which contains two other controls like iblgreeting and imgDefault that are used to display user configurable text and a picture.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GreetingCardMaker.aspx.cs"    Inherits="GreetingCardMaker" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Greeting Card Maker</title>
    <form id="Form1" runat="server">
            <!-- Here are the controls: -->
            Choose a background color:<br />

Screen Layout Designing in a Movie Theater using GridView

In this article, GridView control as a movie screen layout like shown in below images in ASP.Net is explained

Add a Favicon to your ASP.Net page

A favicon is the little image displayed at the left edge of the address bar in most browsers, or on the tab. Adding a Favicon is a nice way to enhance your website and give it a finished look. 

Looking inside Global.asax application file in ASP.NET 3.5

What is Global.asax file: global.asax allows us to write event handlers that react to global events in web applications.

PrintPreviewControl in C#


The PrintPreviewDialog control displays the Print Preview Dialog with all buttons and settings so the users can change their settings before a document goes to the printer. But there are circumstances when you would need to just display print preview without any buttons and options and show only the preview. This is where the PrintPreviewControl can be used. 

Looking deep inside PostBack and ViewState in ASP.NET 3.5


ASP.NET helps in rapid development of web forms in a way similar to our Windows counterpart writes code to develop Windows application for the desktop. Development is rapid in a Windows application for many reasons, i.e. there is no page life cycle etc.

Send an Email with attachment from Outlook, Yahoo, Hotmail, AOL and Gmail


Already loads of information are available on internet for the same purpose. But not all the code is placed at one place. So here is my small effort to accumulate all the code at one place and that is nothing better than this place. Hopefully it will be helpful for the beginners or whoever in needs of it. 

Searching in user profile properties


Using ASP.Net 2005 login controls saves time and effort and produces a professional user management on your ASP.NET web site. User Profile is responsible for extending user properties; but there was a problem faced me that searching is not supported in user profile properties.

Search in Asp.Net


In this article we will see how to implement a search facility in our ASP.Net web site.We can implement such a search facility in our ASP.Net web site for searching for a particular word on a page. For this use a third party control that provides a search box and a search result to control this operation.

BulletedList Control in ASP.NET Framework 4, 3.5, 3.0, 2.0


BulletedList Control will generate or be rendered into a list of items in a bulleted format, even we can attach an image as bulleted style format. BulletedList Control is inherited from ListControl. Here are the list of different Bulleted Styles:

Multi Language Web-Site in ASP.NET


Here we will learn how to translate ASP.Net pages in a user selected language. This article explains step-by-step how to implement your website in multiple languages.