Next step of programming

Just another WordPress.com weblog

Archive for February 2009

Captcha Control Sample (C#, ASP.NET, Server Control)

with 6 comments

In various websites, Captcha control is used for validating the user input and protect web application from the program. Here is one of the sample control for Captcha. It is basic one which can be enhanced further by including more to the image generation and even including the timeout. Or you can add much more to it

This application has two parts

1. CaptchaControl
2. CaptchaControl Sample Project

Captcha control has three files.

1. CaptchaControl (Which is the main control)
2. CaptchaImage (Which generates the Captcha image)
3. CaptchaImageHandler (which will provide the image to browser from the cache).

You can download it from (Captcha Control Sample)

Captcha Sample Control

Captcha Sample Control

Written by A.Sethi

February 26, 2009 at 4:17 am

Posted in ASP.NET, Controls

Tagged with , , , ,

Windows 7 Features Part 1

without comments

Aero Shake Feature

Shaking your windows can make other windows minimize or maximize check out the video

Written by A.Sethi

February 16, 2009 at 7:32 am

Posted in Updates & News

Tagged with ,

Listing All the references of Assembly

without comments

We can list all the references of the assembly in a recursive manner. Here i have avoided System Assemblies since those are not required & they are in circular references. Download the code from this link


private void btnList_Click(object sender, EventArgs e)
{
txtReferences.Text = "";

OpenFileDialog openFileDlg = new OpenFileDialog();
if (openFileDlg.ShowDialog() == DialogResult.OK)
{
txtAssemblyPath.Text = openFileDlg.FileName;
Assembly assembly = Assembly.LoadFrom(txtAssemblyPath.Text);
ListReferences("",assembly);
}

MessageBox.Show("Listing Completed");
}

public void ListReferences(string location, Assembly assembly)
{
//List all references            
string name = assembly.GetName().Name;
string CurrentLocation = location;
txtReferences.Text += CurrentLocation + ">" + name + "\r\n";
location += "--";

if (!name.StartsWith("System.") && !Name.Equals("System"))
{
foreach (AssemblyName assemblyName in assembly.GetReferencedAssemblies())
{
assembly = Assembly.Load(assemblyName);
ListReferences(location, assembly);
Application.DoEvents();
}
}
}

Written by A.Sethi

February 13, 2009 at 7:15 am

Posted in Reflection

Tagged with , , ,

Silverlight for Linux (Moonlight)

without comments

Moonlight Logo

Moonlight Logo

Moonlight is alternative of Silverlight for linux & Unix users. It was the result of technical collaboration between Microsoft and Novell. You can get plugins for Firefox browsers of Moonlight from Novell. They are working on two version of Moonlight, Moonlight 1 & Moonlight 2. For more details check out this link

To download Moonlight 1.0 plugin follow this link

Written by A.Sethi

February 12, 2009 at 5:32 am

Posted in Updates & News

Search your website (Microsoft Indexing Service, C#, ASP.NET)

with one comment

You might have seen various website providing search capabilities to search content within their website. Implementing this in our web application is also easy and for that we have to just use the indexing service to create indexes of our pages. Microsoft is providing indexing service which we can utilise for this purpose.

To understand what is indexing service click this link

Now you might wonder how to get this service in your system. For that follow the steps

1. Goto Control Panel > Add Remove Programs
2. Click “add remove windows component”
3. from the screen select “Indexing service” and install

Installing Indexing Service

Installing Indexing Service

Now you have indexing service in your system. From computer management you can see the indexing service and can manage it. We need to create new catalog which will contain the indexes. To that catalog we will add the directories which are to be indexed.

Indexing Service Management

Indexing Service Management

There are other settings too like Indexing Service usage and etc. For that right click your indexing service node and select All Task > Tune Performance

Tune Performance (Updating Indexes)

Tune Performance (Updating Indexes)

We can now implement this in our web application to search the web pages. Below sample code is written for seaching and displaying the content in the ASP.Net Page

 string connectionString ="Provider=MSIDXS;Data Source=MISSample;";
OleDbConnection connection = new OleDbConnection(connectionString);
connection.Open();

string query = @"SELECT Path, FileName, size, write, attrib, Characterization,
DocTitle FROM SCOPE() " +
"WHERE FREETEXT(Contents, '*" +  txtQuery.Text + "*')";
OleDbCommand command = new OleDbCommand(query, connection);
OleDbDataAdapter adapter = new OleDbDataAdapter(command);

DataSet dataSet = new DataSet();
adapter.Fill(dataSet);

GridView1.DataSource = dataSet.Tables[0];
GridView1.DataBind();
connection.Close();

Sample Output

Sample Application

Sample Application

Written by A.Sethi

February 11, 2009 at 9:51 am

Posted in ASP.NET

Tagged with , , , ,

Get a free Web site (Microsoft)

without comments

Microsoft is now providing free web spaces. Office Live Small Business provides a free web site and hosting, free e-mail, and other online tools for your business

What you will get

  • Web Site
  • Web hosting and Site Design tool (500 MB of Web site storage and easy-to-use design templates )
  • Site Traffic Reports (visitor statistics, page views, top referrers, and more)
  • Contact Manager (sales opportunities, contact information, and track customer interactions)
  • Business Applications (Document Manager, Project Manager, and Workspaces)
  • Click to get started Office Live

    Check the sample dashboard below.

    Free website from microsoft

    Free website from microsoft

Written by A.Sethi

February 11, 2009 at 4:19 am

Posted in Updates & News

Tagged with , , ,

XML Serialization

without comments

Some time we need to save the data in the files which is nothing but the details of the object. For example i am having a application doing vector drawing and i want to save the details of the line object not the image file. How to save the line object and how to get it back. We can use serialization with which we can save our object in file directly and can load it too. Also we can use XML Serialization which is so popular these days.

We have to just mark out objects and class with certain Attributes like XMLRoot, XMLElement, XMLAttribute and so on.


using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;

namespace XMLSerialization
{
static class Program    
{
static void Main()
{
DoSerialization();
}

private static void DoSerialization()
{
Student student1 = new Student { Name = "A", Marks = 23 };
Student student2 = new Student { Name = "B", Marks = 25 };
Students students = new Students();

students.StudentList.Add(student1);
students.StudentList.Add(student2);

XmlSerializer xmlSerialize = new XmlSerializer(students.GetType());
StreamWriter writer = new StreamWriter("a.xml");
xmlSerialize.Serialize(writer, students);
writer.Close();

StreamReader reader = new StreamReader("a.xml");
Students studentsfromFile = (Students)xmlSerialize.Deserialize(reader);

foreach (Student st in studentsfromFile.StudentList)
{
Console.WriteLine("Name : {0} Marks : {1}", st.Name, st.Marks);
}

Console.ReadLine();
}
}

[XmlRoot("Students")]
public class Students    
{
[XmlElement("Student")]
public List<Student> StudentList = new List<Student>();
}

public class Student    
{
[XmlElement("Name")]
public string Name;
[XmlElement("Marks")]
public int Marks;
}
}

Written by A.Sethi

February 10, 2009 at 10:24 am

Sample weather forecast WCF application.

without comments

Here is one WCF webservice sample developed for weather forecasting. Two projects are include one is web application another one is wcf application. Download and check out

Weather Forecast WCF Sample

Weather Forecast WCF Sample

Written by A.Sethi

February 10, 2009 at 8:17 am

Netstat in C#

without comments

Check out how to perform Netstat command functions of DOS in C#. It will list you all the current network connections of your System


using System;
using System.Net;
using System.Net.NetworkInformation;

namespace MyNetstat
{
class Program    
{
static void Main(string[] args)
{
IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();

IPEndPoint[] endPoints = ipProperties.GetActiveTcpListeners();
TcpConnectionInformation[] tcpConnections = ipProperties.GetActiveTcpConnections();

foreach (TcpConnectionInformation info in tcpConnections)
{
Console.WriteLine("Local : " + info.LocalEndPoint.Address.ToString()
+ ":" + info.LocalEndPoint.Port.ToString()
+ "\nRemote : " + info.RemoteEndPoint.Address.ToString()
+ ":" + info.RemoteEndPoint.Port.ToString()
+ "\nState : " + info.State.ToString() + "\n\n");
}
Console.ReadLine();
}
}
}

Written by A.Sethi

February 9, 2009 at 12:09 pm

Listing Domains, Groups, Schemas, User, Computer from DirectoryEntry

with one comment

To list the Domains and their respective Groups, Schemas, User and Computer use DirectoryEntry and enumerate through the Children of the respective Entry. Check out the following code for more understanding

Include Reference to System.DirectoryServices in the project

using System;
using System.Collections.Generic;
using System.Text;
using System.DirectoryServices;

namespace ConsoleApplication2
{
class Program    
{
static void Main(string[] args)
{
DirectoryEntry dirEntry = new DirectoryEntry("WinNT:");

foreach (DirectoryEntry de in dirEntry.Children)
{
if (de.SchemaClassName == "Domain")
{
Console.WriteLine("Domain : " + de.Name);
Console.WriteLine("=================\n");
foreach (DirectoryEntry de2 in de.Children)
{
Console.WriteLine("  Name : " + de2.Name + " \t\t Type : " + de2.SchemaClassName);
}
}
de.Dispose();
}

dirEntry.Dispose();
Console.ReadLine();
}
}
}

Written by A.Sethi

February 9, 2009 at 10:12 am