Jatin kacha's Blog

Archive for October 2010

Intension for the development of this PlugIn is to develop a jQuery pagination which resembles Flicker like

jPager is a jQuery pager plugin, similar to Flickr’s paging interface.

If you have ever visited Flicker photo sharing website, you would have noticed that it display a range of pages with
current page in middle. It also facilitates to have back and forth navigation. If you have very large data spread across
range of pages, and then it leave outs page numbers, displaying an ellipsis instead, followed by the last page number.

It is very integrative jQuery pager Plugin.

Although pager is generally used along with some grid controls, but there may be sometime kind of requirement where
you may require to use jQuery pager control alone itself. For e.g. you may use along with some image gallery,
rotating content, carousel like section etc.

This jQuery pager/Flicker like jQuery pager allows you to creating pagination facility into you application
with minimum effort.

How to use?

  1. Reference jPager.js & jPager.css files in your page
    <script type="text/javascript" language="javascript" src="jquery-1.2.6.min.js" />
    <script type="text/javascript" language="javascript" src="jPager.js" />
    <link href="jPager.css" rel="stylesheet" type="text/css" />
  2. create a HTML container for pager. Put it where you wanted to display your pager require.
    <div id=”content”></div>
  3. Put the following sript in your page.
    <script type=”text/javascript” language=”javascript”>

    $(document).ready(function() { $("#content").pager({ PageCount: 5, currentPage: 1 }); });



  1. Very lighweight & easy to use and easy to integrate. Just one line of code you need to build jQuery pager.
  2. CSS driven so layout is fully costomizable with CSS.
  3. Event driven facility make it easy to call any custom script whenever page get chaged.
  4. Supports upto unlimited pages.
  5. Display custom text for previous & next buttons.
  6. Hide displaying previous & next buttons.

You can download the demo & source code from here.


In this article, I will explain you how to read email from POP3 server or read emails from POP3 server which require SSL. Although I have not developed my own library, I prefer to utilize the available resource.

Well, while being in the development, you have very limited time constraint to go and research on POP3 and then develop your own component.

It is sometime wise decision to go and do the Googling and find out your requirement.

After all we, as developer should “do smart work, not hardwork” J

Anyway, for those who have kind of requirement like reading emails from POP3 server from asp.net, reading email from email server in asp.net etc. Here is the article that you probably find it useful.

Well I had requirement in couple of project where I need to collect emails that are there in particular email’s Inbox. Earlier I was used to with component “Indy.Sockets” component, which really help me to achieve my task.

You may find it from here.


It is an open source socket library. It supports may protocols like SMTP, POP3, NNTP, HTTP, and many more.

Then in one of the module that I come to develop, I need to read Inbox of a Gmail account…!

Well as you know, Gmail requires SSL.

But the drawback with component is it does not support SSL.

So I discover Mailsystem.NET.

MailSystem is a suite of .NET components that provide users with an extensive set of email tools.

I will not explain more in detail on this, rather I will rather just explain how to integrate it and use it.

You can find more information from here..


Once you download it and extract it, you will require to do following steps..

  1. Navigate to “Release” folder in extracted folder.
  2. Find these DLLs: ActiveUp.Net.Mail.dll, ActiveUp.Net.Common.dll, ActiveUp.Net.Dns.dll, ActiveUp.Net.Pop3.dll.
  3. Add reference of these DLLs into your file.

Hurray… are almost done with you configuration.

Now, you only just need to develop your script that fetched and read emails from POP3 server.

So for that, here is the readymade script for you J.

public string[] GetDeliveryFailureEMailsAddress()


Pop3Client pop = new Pop3Client();

System.Collections.Generic.List<string> emails = new System.Collections.Generic.List<string>();

try {

// Connect to the pop3 client

pop.ConnectSsl(SMTPHost, Port, SMTPUserId, SMTPPass);

MessageCollection mc = new MessageCollection();

for (int n = 1; n <= pop.MessageCount; n++) {

Message newMessage = pop.RetrieveMessageObject(n);

//do your stuffs here using newMessage object.


} catch (Pop3Exception pexp) {

} finally {

if (pop.IsConnected) {




return emails.ToArray();


One important part in this script is object initialization.

// Connect to the pop3 client

pop.ConnectSsl(SMTPHost, Port, SMTPUserId, SMTPPass);

As per Gmail, you need to set:

Host: pop.gmail.com

Port: 995

As I told earlier, I want to read email from POP3 server that requires SSL in asp.net.

There are different overloaded constructors that you can use to connect to POP3 server from asp.net.

The library itself is very rich. You can achieve following functionality with POP3 server.

  • Read/Read email from POP3 server in asp.net with CRAM authentication.
  • Retrieve/Read email from POP3 server in asp.net asynchronously.
  • Retrieve/Read email from POP3 server in asp.net with secure connection, like SSL in Gmail.
  • Retrieve/Read only email count from POP3 server in asp.net.
  • Retrieve/Read only email header from POP3 server in asp.net.
  • Retrieve/Read full emails from POP3 server in asp.net.
  • Retrieve/Read full emails to a file from POP3 server in asp.net.

How to convert a value into Enum?

In project, we sometime come across a kind of situation where we need to convert some value to Enum and an Enum object into certain value.

One solution to this is we can write chunk of switch-case statement and return the desired result.

But is there any rationalize method to achieve this? Yes here is the piece of code that you may find it useful. I have implemented it in many of my project and it really helps me reduce some overloaded work for me.

So here is that code for you in which I demonstrate how you can convert a value into Enum object.

using System;

using System.Collections.Generic;

using System.Linq;



static T ConvertValueToEnum<T>(object value, T defaultValue)


Type enumType = Reflection.ExtractEnumType(typeof(T));

if (enumType == null)


ArgumentException(“Type T is not an enumeration”, “T”);




return (T)Enum.Parse(enumType, value.ToString());


catch (ArgumentException)


return defaultValue;



static T ConvertValueToEnum<T>(object value)


Type enumType = Reflection.ExtractEnumType(typeof(T));

if (enumType == null)


ArgumentException(“Type T is not an enumeration”, “T”);


return (T)Enum.Parse(enumType, value.ToString());



Here there are two overloaded methods. All you have to do is pass your desired enumeration object. The method itself will identify and return attached valued to that particular Enum object.

Happy programming…

How the necessities arise?

Necessity is mother of invention.

I was assigned a task to develop a restaurant portal.

The basic aim behind creation of this project is to have a marketplace for all restaurant owner or hotel business, and provide end user with integrative google map services so that they visualize realtime.

If we are supposed to insert a simple google map, then we just have to insert a piece javascript code, and boom you are done.

But in my project, I have requirement where different restaurant/hotel owner register and give us their details and addresses.

So, What is Google Map API?

The Google Maps API lets you embed Google Maps in your own web pages with JavaScript. The API provides a number of utilities for manipulating maps and adding content to the map through a variety of services, allowing you to create robust maps applications on your website.

All map related functionalities can be achieved as seen on http://maps.google.com/

Then what was hurdle for me in using Map API?

These are the pure JavaScript code..!! You can develop whatever rich Map application you wanted to develop by writing piece of JavaScript codes.

Actually to host a map on your page, you need to have two parameters, Latitude & Longitude. But how do I get lat. and long. from server side scripting?

But I had no idea how to call Google Map API from C#/VB.NET.

So for my project, as usual, I start googling to find out my piece of sweet.

After searching for couple of hours, I come across this good article.


Here the author explained the how to obtain the latitude and longitude co-ordinates for an address using the Google Maps API.

But again here, it is pure JavaScript that utilize Google Map API to get lat & long of any address. But my problem is still there?

Hurrray….. I found the solution

Then accidently I come to across Google Maps API Web Services.

It is basically Maps API Web Services, a collection of HTTP interfaces to Google services providing geographic data for your maps applications.

In the documentation (http://code.google.com/apis/maps/documentation/webservices/),

I see that you can utilize Google Map API web service by making HTTP request to a specific URL, providing necessary parameters with URL. Which in return, gives a response in desired format.

You can get response inform of JSON or XML.

Say for e.g. it can be called like this URL

http://maps.google.com/maps/geo?q=khandala, maharashtra&output=xml&key=xxxxxxxxxxxxxx

Paste it into your browser and you will receive a XML response.

Immediately, I get one “Mantos (Dimag ki batti jala de)” and found a clue J

I thought why not to develop a library that make a call to this URL and parse the returned output to get lat & long…!!?

So for that purpose I write this library.

Obviously, before doing all these, you will need to register with Google Map API and get a key so that you can utilize their API.

Sign up and get a Google Maps API Key.  You will need one for the domain name of where you will be hosting the map.  You can get your API Key from here (http://code.google.com/apis/maps/signup.html)

Following is the complete code that I used to call Google Map Geocoding API from Asp.net.

All you have to do Is to just create a class file and paste the following code. And you are ready to call Google Map Geocoding API.

How to call Geocoding API from Asp.net?

Step 1

/// Resolve addresses into latitude/longitude coordinates using Google MAP API webservices

public static class Geocoder{

private static string _GoogleMapsKey = Config.getAppSetting(“GoogleMapsKey”);

/// Google.com Geocoder

/// Url request to

/// http://maps.google.com/maps/geo?q=your address&output=xml&key=xxxxxxxxxxxxxx

public static Geolocation? ResolveAddress(string query)


if (string.IsNullOrEmpty(_GoogleMapsKey))

_GoogleMapsKey = ConfigurationManager.AppSettings[“GoogleMapsKey”];

string url = http://maps.google.com/maps/geo?q={0}&output=xml&key=” + _GoogleMapsKey;

url = String.Format(url, query);

XmlNode coords = null;


string xmlString = GetUrl(url);

XmlDocument xd = new XmlDocument();


XmlNamespaceManager xnm = new XmlNamespaceManager(xd.NameTable);

coords = xd.GetElementsByTagName(“coordinates”)[0];


catch { }

Geolocation? gl = null;

if (coords != null){

string[] coordinateArray = coords.InnerText.Split(‘,’);

if (coordinateArray.Length >= 2)


gl = new Geolocation(Convert.ToDecimal(coordinateArray[1].ToString()), Convert.ToDecimal(coordinateArray[0].ToString()));



return gl;


public static Geolocation? ResolveAddress(string address, string city, string state, string postcode, string country)


return ResolveAddress(address + “,” + city + “,” + state + “,” + postcode + ” “ + country);



/// Retrieve a Url via WebClient

private static string GetUrl(string url)


string result = string.Empty;

System.Net.WebClient Client = new WebClient();

using (Stream strm = Client.OpenRead(url))


StreamReader sr = new StreamReader(strm);

result = sr.ReadToEnd();


return result;



public struct Geolocation


public decimal Lat;

public decimal Lon;

public Geolocation(decimal lat, decimal lon)


Lat = lat;

Lon = lon;


public override string ToString()


return “Latitude: “ + Lat.ToString() + ” Longitude: “ + Lon.ToString();


public string ToQueryString()


return “+to:” + Lat + “%2B” + Lon;



Step 2

Now, you just need to put a key in AppSetting section that hold your Google Map API key.

Step 3

I have provided 2 overloaded methods to call Geocoding Map API Webservice, named ResolveAddress.

Say for e.g. you can call method like this.

Geocoder.ResolveAddress(“University road”,”rajkot”,”gujarat”,””,”India”)

I hope this will solve your purpose, those who wanted to develop Geocoding application, those who want to access Google Map Webservice API from c#/vb.net.

Happy programming…

My tweets