<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2559055593203508155</id><updated>2011-09-02T03:37:57.380-07:00</updated><category term='Python'/><category term='Events / Conferences'/><category term='Mobile'/><category term='Windows XP'/><category term='Windows Vista'/><category term='XSLT'/><category term='XSL'/><category term='Visual Studio.NET'/><category term='SilverLight'/><category term='J#'/><category term='SQL Server'/><category term='SharePoint'/><category term='Jobs'/><category term='SQL Server 2005'/><category term='XML'/><category term='F#'/><category term='Java'/><category term='Exams and Certifications'/><category term='XAML'/><category term='Dynamics Axapta'/><category term='ASP.NET'/><category term='ADO.NET'/><category term='X++'/><category term='C#'/><category term='PHP'/><category term='Videos'/><category term='TSql'/><category term='Community'/><category term='Cutting-Edge Tech'/><category term='Coding Standards'/><category term='Technology News'/><category term='PL-Sql'/><category term='Visual Studio.NET 2010'/><category term='HTML'/><category term='OOP'/><category term='PostGraduate'/><category term='Miscellaneous'/><category term='Google Adsense'/><category term='JavaScript'/><category term='Tricks'/><category term='Earn Money'/><category term='Architecture / Design'/><title type='text'>Developers House</title><subtitle type='html'>Developers house is a blog for posting technical articles in different technology like Microsft, Java, Oracle ..etc</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default?start-index=101&amp;max-results=100'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>117</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-8965737149803516629</id><published>2010-05-26T01:27:00.001-07:00</published><updated>2010-05-26T01:27:42.071-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='Miscellaneous'/><category scheme='http://www.blogger.com/atom/ns#' term='Technology News'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Test Driven Development Tutorial in C# 4.0</title><content type='html'>&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Introduction - Defining the Battlefield&lt;/b&gt;     &lt;br /&gt;This tutorial is an short introduction to using Test Driven Development (TDD) in &lt;a href="http://www.c-sharpcorner.com/UploadFile/dommym/1303/Default.aspx"&gt;Visual Studio&lt;img title="clip_image001" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="10" alt="clip_image001" src="http://lh3.ggpht.com/_iuwZHhydmEs/S_zaHkIcTSI/AAAAAAAABLo/LjSyd4LnrNM/clip_image001%5B5%5D.gif?imgmax=800" width="10" border="0" /&gt;&lt;/a&gt; 2010 (VS2010) with C#. Like most of my examples it's based on a game.&amp;#160; &lt;br /&gt;By completing this tutorial you will:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Get a taste of TDD through a series of small iterations; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.c-sharpcorner.com/UploadFile/dommym/1303/Default.aspx"&gt;Learn&lt;/a&gt; how VS2010 provides TDD support through a number of new features; and &lt;/li&gt;    &lt;li&gt;Learn a number of C# 4.0 features. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;CannonAttack is a simple text based game in which a player enters an angle and velocity of a cannonball to hit a target at a given distance. The game uses a basic formula for calculating the trajectory of the cannonball and the player keeps taking turns at shooting at the target until it has been hit. I won't go into TDD theory in any great detail now, but you should check out the number of great references to TDD including:    &lt;br /&gt;&lt;a href="http://en.wikipedia.org/wiki/Test_driven_development"&gt;http://en.wikipedia.org/wiki/Test_driven_development&lt;/a&gt;     &lt;br /&gt;&lt;a href="http://www.codeproject.com/KB/dotnet/tdd_in_dotnet.aspx"&gt;http://www.codeproject.com/KB/dotnet/tdd_in_dotnet.aspx&lt;/a&gt;     &lt;br /&gt;&lt;b&gt;&lt;a href="http://www.c-sharpcorner.com/UploadFile/rmcochran/test_driven_development10072006125103PM/test_driven_development.aspx"&gt;C# .NET 2.0 Test Driven Development &lt;/a&gt;&lt;/b&gt;&lt;b&gt;by&lt;/b&gt;&lt;b&gt; &lt;a href="http://www.c-sharpcorner.com/Authors/AuthorDetails.aspx?AuthorID=rmcochran"&gt;Matthew Cochran&lt;/a&gt;&lt;/b&gt;     &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd998313(VS.100).aspx"&gt;http://msdn.microsoft.com/en-us/library/dd998313(VS.100).aspx&lt;/a&gt;     &lt;br /&gt;The following are the fundamental steps of a TDD iteration:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;RED - take a piece of functionality and build a test for it and make it fail the test by writing a minimum amount of code(basically just get it to compile and run the test); &lt;/li&gt;    &lt;li&gt;GREEN - write minimal code for the test to make it succeed; and &lt;/li&gt;    &lt;li&gt;REFACTOR - clean up and reorganize the code and ensure it passes the test and any previous tests. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In this tutorial we will be progressing through a number of iterations of the TDD cycle to produce a fully functional simple application. Each iteration will pick up one or more of the requirements/specs from our list (see The CannonAttack Requirements/Specs below). We won't test for absolutely everything and some of the tests are fairly basic and simplistic, but I am just trying to keep things reasonably simple at this stage    &lt;br /&gt;&lt;b&gt;VS2010 and C# 4.0:&lt;/b&gt;     &lt;br /&gt;This tutorial covers the use of VS2010 and targets a number of features of C# 4.0,&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Generating stubbs for TDD in VS2010; &lt;/li&gt;    &lt;li&gt;Test Impact View in VS2010; &lt;/li&gt;    &lt;li&gt;Tuples; and &lt;/li&gt;    &lt;li&gt;String.IsNullOrWhiteSpace method. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;There are many more features of C#4.0 and we will be covering them in future tutorials.    &lt;br /&gt;&lt;b&gt;What you need:&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;This is a C# tutorial so a background in C# would be very useful; and &lt;/li&gt;    &lt;li&gt;VS 2010 professional or above (This tutorial has been tested against VS2010 rtm and beta2). &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;The CannonAttack Requirements/Specs:&lt;/b&gt;     &lt;br /&gt;The following is a combination of Requirements and Specifications that will give us some guide in terms of the application we are trying to build:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Windows Console Application; &lt;/li&gt;    &lt;li&gt;Player identified by an id, default is set to a constant &amp;quot;Human&amp;quot;; &lt;/li&gt;    &lt;li&gt;Single player only, no multi-play yet; &lt;/li&gt;    &lt;li&gt;Allow player to set Angle and Speed of the Cannon Ball to Shoot at a Target; &lt;/li&gt;    &lt;li&gt;Target Distance is simply the distance of the Cannon to Target, and is created randomly by default but can be overridden; &lt;/li&gt;    &lt;li&gt;Angle and Speed needs to be validated (specifically not greater than 90 degrees and Speed not greater than speed of light); &lt;/li&gt;    &lt;li&gt;Max distance for target is 20000 meters; &lt;/li&gt;    &lt;li&gt;Base the algorithm for the calculation of the cannons trajectory upon the following C# code (distance and height is meters and velocity is meters per second):      &lt;br /&gt;distance = velocity * Math.Cos(angleInRadians) * time;       &lt;br /&gt;height = (velocity * Math.Sin(angleInRadians) * time) - (GRAVITY * Math.Pow(time, 2)) / 2; &lt;/li&gt;    &lt;li&gt;A hit occurs if the cannon is within 50m of the target; &lt;/li&gt;    &lt;li&gt;Display number of shots for a hit &lt;/li&gt;    &lt;li&gt;Game text will be similar to following: &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Welcome to Cannon Attack    &lt;br /&gt;Target Distance:12621m     &lt;br /&gt;Please Enter Angle:40     &lt;br /&gt;Please Enter Speed:350     &lt;br /&gt;Missed cannonball landed at 12333m     &lt;br /&gt;Please Enter Angle:45     &lt;br /&gt;Please Enter Speed:350     &lt;br /&gt;Hit - 2 Shots     &lt;br /&gt;Would you like to play again (Y/N)     &lt;br /&gt;Y     &lt;br /&gt;Target Distance:2078m     &lt;br /&gt;Please Enter Angle:45     &lt;br /&gt;Please Enter Speed:100     &lt;br /&gt;Missed cannonball landed at 1060m     &lt;br /&gt;Please Enter Angle:45     &lt;br /&gt;Please Enter Speed:170     &lt;br /&gt;Missed cannonball landed at 3005m     &lt;br /&gt;Please Enter Angle:45     &lt;br /&gt;Please Enter Speed:140     &lt;br /&gt;Hit - 3 shots&amp;#160; &lt;br /&gt;Would you like to play again (Y/N)     &lt;br /&gt;N     &lt;br /&gt;Thanks for playing CannonAttack&lt;/p&gt;  &lt;p&gt;OK so now we are ready to code, let's go...    &lt;br /&gt;&lt;b&gt;Iteration 1 - Creating the Cannon&lt;/b&gt;     &lt;br /&gt;&lt;b&gt;&lt;u&gt;Steps&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Start Visual Studio &lt;/li&gt;    &lt;li&gt;Click New Project... &lt;/li&gt;    &lt;li&gt;From the Windows submenu select Console Application as below      &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/S_zaIaKjrVI/AAAAAAAABLs/V98AA-JhO_Q/s1600-h/clip_image002%5B4%5D.gif"&gt;&lt;img title="clip_image002" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="372" alt="clip_image002" src="http://lh6.ggpht.com/_iuwZHhydmEs/S_zaJsPbMoI/AAAAAAAABLw/bRJAOwjB2dc/clip_image002_thumb%5B1%5D.gif?imgmax=800" width="532" border="0" /&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Call the application CannonAttack and click OK &lt;/li&gt;    &lt;li&gt;Right click on Program.cs and select Rename and call the file CannonAttack.cs. &lt;/li&gt;    &lt;li&gt;If you see the following select YES.      &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/S_zaK0tRnZI/AAAAAAAABL0/xMagiE7gNig/s1600-h/clip_image003%5B6%5D.gif"&gt;&lt;img title="clip_image003" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="109" alt="clip_image003" src="http://lh6.ggpht.com/_iuwZHhydmEs/S_zaLmyTscI/AAAAAAAABL4/yVW9reT95_Q/clip_image003_thumb%5B1%5D.gif?imgmax=800" width="533" border="0" /&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;When the &lt;a href="http://www.c-sharpcorner.com/UploadFile/dommym/1303/Default.aspx"&gt;solution&lt;img title="clip_image001[1]" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="10" alt="clip_image001[1]" src="http://lh4.ggpht.com/_iuwZHhydmEs/S_zaMLSD4-I/AAAAAAAABL8/Y2vlE4yKzcw/clip_image001%5B1%5D%5B2%5D.gif?imgmax=800" width="10" border="0" /&gt;&lt;/a&gt; has loaded right click on the solution in Solution Explorer and select ADD-&amp;gt;NEW PROJECT. If you can't see the Solution Explorer select from Tools-&amp;gt;Options-&amp;gt;Projects and Solutions and tick always show solution &lt;/li&gt;    &lt;li&gt;Select Test Project and call it CannonAttackTest as below:      &lt;br /&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/S_zaNF6r7vI/AAAAAAAABMA/4K68y-weRGY/s1600-h/clip_image004%5B4%5D.gif"&gt;&lt;img title="clip_image004" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="307" alt="clip_image004" src="http://lh3.ggpht.com/_iuwZHhydmEs/S_zaN0WnUTI/AAAAAAAABME/BhKpxOtpWGU/clip_image004_thumb%5B1%5D.gif?imgmax=800" width="479" border="0" /&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Click OK &lt;/li&gt;    &lt;li&gt;Right click on the CannonAttackTest project and make it the startup project by selecting Set as Startup Project. &lt;/li&gt;    &lt;li&gt;Rename the UnitTest1.cs to CannonAttackTest.cs &lt;/li&gt;    &lt;li&gt;If you see the following select YES&amp;#160; &lt;br /&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/S_zaO9jSmWI/AAAAAAAABMI/rhKUNoirTpE/s1600-h/clip_image003%5B1%5D%5B3%5D.gif"&gt;&lt;img title="clip_image003[1]" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="126" alt="clip_image003[1]" src="http://lh5.ggpht.com/_iuwZHhydmEs/S_zaQAEYyrI/AAAAAAAABMM/S_lXOpWXdEY/clip_image003%5B1%5D_thumb%5B1%5D.gif?imgmax=800" width="619" border="0" /&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;You should see the Solution explorer appear as:      &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/S_zaQ2pVA1I/AAAAAAAABMQ/7Yo-YSd7X58/s1600-h/clip_image005%5B4%5D.gif"&gt;&lt;img title="clip_image005" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="460" alt="clip_image005" src="http://lh5.ggpht.com/_iuwZHhydmEs/S_zaRhgWS5I/AAAAAAAABMU/7aTe4bq0WmM/clip_image005_thumb%5B1%5D.gif?imgmax=800" width="249" border="0" /&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Open the code window for the CannonAttackTest.cs file and you should see the default test method. The [TestMethod] attribute above a method in this file indicates VS2010 will add this method as a unit test. &lt;/li&gt;    &lt;li&gt;Replace the default test method:      &lt;br /&gt;[TestMethod]       &lt;br /&gt;public void TestMethod1()       &lt;br /&gt;{       &lt;br /&gt;}       &lt;br /&gt;with the following:       &lt;br /&gt;[TestMethod]       &lt;br /&gt;public void TestCannonIDValid()       &lt;br /&gt;{       &lt;br /&gt;Cannon cannon = new Cannon();       &lt;br /&gt;} &lt;/li&gt;    &lt;li&gt;This won't compile but right click on Cannon and select Generate-&amp;gt;New Type &lt;/li&gt;    &lt;li&gt;When the following screen appears change the Project to CannonAttack and accept the other defaults as below:      &lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/S_zafM5OiyI/AAAAAAAABMY/LRxdc-gVzO0/s1600-h/clip_image006%5B4%5D.gif"&gt;&lt;img title="clip_image006" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="451" alt="clip_image006" src="http://lh6.ggpht.com/_iuwZHhydmEs/S_zaf0RqgkI/AAAAAAAABMc/NCHdI0KiHJs/clip_image006_thumb%5B1%5D.gif?imgmax=800" width="437" border="0" /&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Now change the TestCannonIDValid method to:      &lt;br /&gt;[TestMethod]       &lt;br /&gt;public void TestCannonIDValid()       &lt;br /&gt;{       &lt;br /&gt;Cannon cannon = new Cannon();       &lt;br /&gt;Assert.IsNotNull(cannon.ID);       &lt;br /&gt;} &lt;/li&gt;    &lt;li&gt;Now the solution won't compile as the ID property does not exist &lt;/li&gt;    &lt;li&gt;Right click on the ID and select Generate-&amp;gt;Property (ID has now been added to the Cannon class). This creates an auto property which for the moment will hopefully compile. &lt;/li&gt;    &lt;li&gt;Save all projects and hit CTRL-F5. This will start the Tests running (not F5 in debug mode because debug mode will by default stop if an Assert fails). &lt;/li&gt;    &lt;li&gt;You should see in the tests window:      &lt;br /&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/S_zagqkhLKI/AAAAAAAABMg/2h6o7Wgw0MA/s1600-h/clip_image007%5B4%5D.gif"&gt;&lt;img title="clip_image007" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="156" alt="clip_image007" src="http://lh5.ggpht.com/_iuwZHhydmEs/S_zahW27RKI/AAAAAAAABMk/X49dIT7oUlQ/clip_image007_thumb%5B1%5D.gif?imgmax=800" width="603" border="0" /&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;The test failed. This is correct and as expected the first phase of the TDD iteration has occurred RED - failed!!! &lt;/li&gt;    &lt;li&gt;So now that we have a red lets get this test to pass. &lt;/li&gt;    &lt;li&gt;Select cannon.cs in the CannonAttack project and make the following change to the ID property:      &lt;br /&gt;public string ID       &lt;br /&gt;{       &lt;br /&gt;get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;return &amp;quot;Human&amp;quot;;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;} &lt;/li&gt;    &lt;li&gt;Now run the test CTRL-F5 and we should see:      &lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/S_zaiEJ-kQI/AAAAAAAABMo/czxyOkwCBGk/s1600-h/clip_image008%5B4%5D.gif"&gt;&lt;img title="clip_image008" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="109" alt="clip_image008" src="http://lh4.ggpht.com/_iuwZHhydmEs/S_zajIXbajI/AAAAAAAABMs/OilAl3x48NU/clip_image008_thumb%5B1%5D.gif?imgmax=800" width="612" border="0" /&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;We have just completed the second stage of a TDD cycle GREEN - Pass!!!! &lt;/li&gt;    &lt;li&gt;So the next stage is to refractor, and it would be nice to make a couple of changes to the class to clean it up, so that the class now looks like:      &lt;br /&gt;using System;       &lt;br /&gt;using System.Collections.Generic;       &lt;br /&gt;using System.Linq;       &lt;br /&gt;using System.Text;       &lt;br /&gt;namespace CannonAttack       &lt;br /&gt;{       &lt;br /&gt;public sealed class Cannon       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;private readonly string CANNONID = &amp;quot;Human&amp;quot;;       &lt;br /&gt;private string CannonID;       &lt;br /&gt;public string ID       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;get       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;return (String.IsNullOrWhiteSpace(CannonID)) ? CANNONID : CannonID;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;set       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; CannonID = value;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;} &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;We have made this class sealed so that it is not inherited by anything. Also, we have added a readonly string to store a default ID if not set by the user. I am going to use runtime constants (readonly) because they are more flexible than compile time constants (const) and if you are interested check out Bill Wagner's book (effective C# - 50 Ways to Improve your C#) for further details.    &lt;br /&gt;Let's run the test again. Again it should compile and pass tests because although we have made some changes to the code, we should not have impacted the tests and this is an important part of the Refactor phase. We should make the changes we need to make the code more efficient and reusable, but it is critical that the same test that we made pass in the Green phase still passes in the Refactor phase.     &lt;br /&gt;The refactoring is complete. Now for ITERATION 2 of the CannonAttack project.     &lt;br /&gt;&lt;b&gt;Iteration 2 - One Canon, and only one Cannon - Using the Singleton Pattern. &lt;/b&gt;    &lt;br /&gt;Like the previous iteration we will pick an element of functionality and work through the same sequence again RED-&amp;gt;GREEN-&amp;gt;REFACTOR. Our next requirement is to allow only a single player. Given that we can allow 1 player we really should only use one instance, let's create a test for only one instance of the cannon object. We can compare two objects to ensure they are pointing at the same instance like (obj == obj2).&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Add a new test beneath the first test in cannonattacktest.cs and our method looks like:      &lt;br /&gt;[TestMethod]       &lt;br /&gt;public void TestCannonMultipleInstances()       &lt;br /&gt;{       &lt;br /&gt;Cannon cannon = new Cannon();       &lt;br /&gt;Cannon cannon2 = new Cannon();       &lt;br /&gt;Assert.IsTrue(cannon == cannon2);       &lt;br /&gt;} &lt;/li&gt;    &lt;li&gt;Run the tests by hitting CTRL-F5. We 1 Pass and 1 fail (our new test) so we are at RED again.      &lt;br /&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/S_zajuRBjqI/AAAAAAAABMw/MafIuco4VWc/s1600-h/clip_image009%5B4%5D.gif"&gt;&lt;img title="clip_image009" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="156" alt="clip_image009" src="http://lh3.ggpht.com/_iuwZHhydmEs/S_zakRatfWI/AAAAAAAABM0/d5vwPRjqoIw/clip_image009_thumb%5B1%5D.gif?imgmax=800" width="541" border="0" /&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;The reason that this failed is we have created two different instances. What we need is the singleton pattern to solve our problem. I have a great book on patterns called HEAD FIRST &lt;a href="http://www.c-sharpcorner.com/UploadFile/dommym/1303/Default.aspx"&gt;DESIGN&lt;img title="clip_image001[2]" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="10" alt="clip_image001[2]" src="http://lh5.ggpht.com/_iuwZHhydmEs/S_zalMJwehI/AAAAAAAABM4/lZ8W7oFSSlE/clip_image001%5B2%5D%5B2%5D.gif?imgmax=800" width="10" border="0" /&gt;&lt;/a&gt; PATTERNS if you want to know more about design patterns it's a great start - sure its Java but the code is so close to C# you should not have any real problems. &lt;/li&gt;    &lt;li&gt;We are going to use the singleton pattern to meet the requirement of a single player. Really we don't want multiple instances of cannons hanging around - 1 and only 1 instance is needed. Insert the following Singleton code below the property for the ID.&amp;#160; &lt;br /&gt;private static Cannon cannonSingletonInstance;       &lt;br /&gt;private Cannon()       &lt;br /&gt;{       &lt;br /&gt;}       &lt;br /&gt;public static Cannon GetInstance()       &lt;br /&gt;{       &lt;br /&gt;if (cannonSingletonInstance == null)       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; cannonSingletonInstance = new Cannon();       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;return cannonSingletonInstance;       &lt;br /&gt;} &lt;/li&gt;    &lt;li&gt;If we try to run the tests we won't compile because the cannon object can't be created with Cannon cannon = new Cannon(); So make sure that we use Cannon.GetInstance() instead of new Cannon(). The two test methods should now look like:      &lt;br /&gt;[TestMethod]       &lt;br /&gt;public void TestCannonIDValid()       &lt;br /&gt;{       &lt;br /&gt;Cannon cannon = Cannon.GetInstance();       &lt;br /&gt;Assert.IsNotNull(cannon.ID);       &lt;br /&gt;}       &lt;br /&gt;[TestMethod]       &lt;br /&gt;public void TestCannonMultipleInstances()       &lt;br /&gt;{       &lt;br /&gt;Cannon cannon = Cannon.GetInstance();       &lt;br /&gt;Cannon cannon2 = Cannon.GetInstance();       &lt;br /&gt;Assert.IsTrue(cannon == cannon2);       &lt;br /&gt;} &lt;/li&gt;    &lt;li&gt;Run the Tests again CTRL-F5      &lt;br /&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/S_zamdjKPeI/AAAAAAAABM8/gK81Q-WpJAU/s1600-h/clip_image010%5B4%5D.gif"&gt;&lt;img title="clip_image010" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="147" alt="clip_image010" src="http://lh5.ggpht.com/_iuwZHhydmEs/S_zam0mN7ZI/AAAAAAAABNA/utpJx1Q4INk/clip_image010_thumb%5B1%5D.gif?imgmax=800" width="524" border="0" /&gt;&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;This time they pass GREEN so time to refactor. We are going to change our Singleton code because although the code works (and is pretty much 100% the same as the singleton code in the HEAD FIRST DESIGN PATTERNS Book) it is not thread safe in C# (see http://msdn.microsoft.com/en-us/library/ff650316.aspx) So we replace the original singleton code with:&lt;/p&gt;  &lt;p&gt;private static Cannon cannonSingletonInstance;    &lt;br /&gt;static readonly object padlock = new object();     &lt;br /&gt;private Cannon()     &lt;br /&gt;{     &lt;br /&gt;}     &lt;br /&gt;public static Cannon GetInstance()     &lt;br /&gt;{     &lt;br /&gt;lock (padlock)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;if (cannonSingletonInstance == null)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; cannonSingletonInstance = new Cannon();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;return cannonSingletonInstance;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;}     &lt;br /&gt;The block inside the lock ensures that only one thread enters this block at any given time. Given the importance of determining if there is an instance or not, we should definitely use the lock.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Run the all the tests again CTRL-F5 and they should all pass &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;That's the end of the second iteration and I think you should be getting the hang of it by now, so lets get onto the 3rd iteration.    &lt;br /&gt;&lt;b&gt;Iteration 3 - Angling for something...&lt;/b&gt;     &lt;br /&gt;We will add another test method. This time we want to ensure that an incorrect angle (say 95 degrees) will not hit. So we need a Shoot method and a return type (lets keep it simple and make it a Boolean for now).&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Add the following test below the last test: &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;[TestMethod]    &lt;br /&gt;public void TestCannonShootIncorrectAngle()     &lt;br /&gt;{     &lt;br /&gt;Cannon cannon = Cannon.GetInstance();     &lt;br /&gt;Assert.IsFalse(cannon.Shoot(95, 100));     &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Of &lt;a href="http://www.c-sharpcorner.com/UploadFile/dommym/1303/Default.aspx"&gt;course&lt;/a&gt; the compiler will complain and we get it to compile by right clicking on the Shoot method and select Generate-&amp;gt;Method Stub. &lt;/li&gt;    &lt;li&gt;Change the return type of the stub (in Cannon.cs) to a bool so that it will compile. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;public bool Shoot(int p, int p_2)    &lt;br /&gt;{     &lt;br /&gt;throw new NotImplementedException();     &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Now hit CTRL-F5 and we see that the first two tests should still pass but our new test fails as this is the RED phase again. &lt;/li&gt;    &lt;li&gt;So open Cannon.cs in the CannonAttack project, and replace the generated Shoot method with: &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;public bool Shoot(int angle, int velocity)    &lt;br /&gt;{     &lt;br /&gt;if (angle &amp;gt; 90 || angle &amp;lt; 0) //Angle must be between 0 //and 90 degrees     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;return false;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;return true; //Not going to do the calculation just yet     &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Run the tests again and all three tests now pass so again :GREEN, so now back to refactor. &lt;/li&gt;    &lt;li&gt;We need to add two extra readonly integers to the class. Insert them at the top of the class. We will add them as public so that they are exposed to the console application eventually.      &lt;br /&gt;public static readonly int MAXANGLE = 90;       &lt;br /&gt;public static readonly int MINANGLE = 1; &lt;/li&gt;    &lt;li&gt;We want to refactor the Shoot method, so this now looks like:      &lt;br /&gt;public Tuple&amp;lt;bool, string&amp;gt; Shoot(int angle, int velocity)       &lt;br /&gt;{       &lt;br /&gt;if (angle &amp;gt; MAXANGLE || angle &amp;lt; MINANGLE) //Angle must be //between 0 and 90 degrees       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {       &lt;br /&gt;return Tuple.Create(false, &amp;quot;Angle Incorrect&amp;quot;);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br /&gt;return Tuple.Create(true, &amp;quot;Angle OK&amp;quot;); //Not //going to do the calculation just yet       &lt;br /&gt;}       &lt;br /&gt;We have changed the interface of the method so it returns a Tuple indicating if its a hit (BOOL) and also a message (STRING) containing the display text. The Tuple is a feature of C# 4.0. used to group a number of types together and we have used it in conjunction with the type inference of the var to give a neat and quick way to handle the messages from our shoot method. See the following article for further information:&lt;a href="http://www.davidhayden.me/2009/12/tuple-in-c-4-c-4-examples.html"&gt;http://www.davidhayden.me/2009/12/tuple-in-c-4-c-4-examples.html&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;To handle the change to the shoot method we change our test to: &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;[TestMethod]    &lt;br /&gt;public void TestCannonShootAngleIncorrect()     &lt;br /&gt;{     &lt;br /&gt;var shot = cannon.Shoot(95, 100);     &lt;br /&gt;Assert.IsFalse(shot.Item1);     &lt;br /&gt;}     &lt;br /&gt;You will also notice now we have removed the object initialization of the cannon in our test method. The reason we have done this is we have moved that to the Class Initialize method of CannonAttackTest.cs. To do this simply uncomment out the two lines below:&lt;/p&gt;  &lt;p&gt;[ClassInitialize()]    &lt;br /&gt;public static void CannonTestsInitialize(TestContext testContext)     &lt;br /&gt;{     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;Rename MyClassInitialize to CannonTestsInitialize.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Now just declare a cannon object for the class and add the object initialize code as this method is called every time we run our test. It means every test can remove that one line of code and now looks like the following (note we have removed a number of commented test methods that visual studio creates by default): &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;using System;    &lt;br /&gt;using System.Text;     &lt;br /&gt;using System.Collections.Generic;     &lt;br /&gt;using System.Linq;     &lt;br /&gt;using Microsoft.VisualStudio.TestTools.UnitTesting;     &lt;br /&gt;using CannonAttack;     &lt;br /&gt;namespace CannonAttackTest     &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; [TestClass]     &lt;br /&gt;public class CannonAttackTest     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;private static Cannon cannon;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [ClassInitialize()]     &lt;br /&gt;public static void CannonTestsInitialize(TestContext testContext)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; cannon = Cannon.GetInstance();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [TestMethod]     &lt;br /&gt;public void TestCannonIDValid()     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;Assert.IsNotNull(cannon.ID);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [TestMethod]     &lt;br /&gt;public void TestCannonMultipleInstances()     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;Cannon cannon2 = Cannon.GetInstance();     &lt;br /&gt;Assert.IsTrue(cannon == cannon2);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [TestMethod]     &lt;br /&gt;public void TestCannonShootAngleIncorrect()     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;var shot = cannon.Shoot(95, 100);     &lt;br /&gt;Assert.IsFalse(shot.Item1);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Now let's compile and run the tests CTRL-F5 and we'll find that they should all pass so we are finished the 3rd iteration. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;Iteration 4 - That's a pretty fast cannonball&lt;/b&gt;     &lt;br /&gt;The next area of functionality, looking at the requirements, is to validate the incorrect speed. Just incase you are worrying about this validation...     &lt;br /&gt;&amp;quot;Nothing in the universe can travel at the speed of light, they say, forgetful of the shadow's speed.&amp;quot; ~Howard Nemerov     &lt;br /&gt;Now that we are informed, let's write the test...&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Add the following below the TestCannonShootAngleIncorrect method &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;[TestMethod]    &lt;br /&gt;public void TestCannonShootVelocityGreaterThanSpeedOfLight()     &lt;br /&gt;{     &lt;br /&gt;var shot = cannon.Shoot(45, 300000001);     &lt;br /&gt;Assert.IsFalse(shot.Item1);     &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;So we run the tests and it will fail RED because the validation isn't complete in the Shoot method . We add the code needed into shoot method just under the validation code for the incorrect angle: &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;if (velocity &amp;gt; 300000000)    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; return Tuple.Create(false, &amp;quot;Velocity of the cannon cannot travel faster than the speed of light&amp;quot;);     &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Run the tests again and this time they all pass - GREEN &lt;/li&gt;    &lt;li&gt;Time to refactor, but this time lets use a new feature in VS2010 that allows us to determine the impact of a code change on the Test project. &lt;/li&gt;    &lt;li&gt;Select from the menu TEST-&amp;gt;Windows-&amp;gt;Test Impact View :      &lt;br /&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/S_zani_1pFI/AAAAAAAABNE/eLc-T2aokB8/s1600-h/clip_image011%5B4%5D.gif"&gt;&lt;img title="clip_image011" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="353" alt="clip_image011" src="http://lh4.ggpht.com/_iuwZHhydmEs/S_zaoXdShhI/AAAAAAAABNI/ZxD3oI9VVK0/clip_image011_thumb%5B1%5D.gif?imgmax=800" width="437" border="0" /&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;The Test Impact View will appear on the right of your IDE and if you haven't used Test Impact View yet you will see:      &lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/S_za5RsVADI/AAAAAAAABNM/pPgSxy-ZA0Y/s1600-h/clip_image012%5B4%5D.gif"&gt;&lt;img title="clip_image012" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="475" alt="clip_image012" src="http://lh6.ggpht.com/_iuwZHhydmEs/S_za6BcxnTI/AAAAAAAABNQ/YfMYdKAXhhI/clip_image012_thumb%5B1%5D.gif?imgmax=800" width="361" border="0" /&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Click the Enable test impact data collection in the active test settings link and then select OK on the next dialog. You must do this for each solution you use test impact view. &lt;/li&gt;    &lt;li&gt;Build and Run CTRL-F5 all the tests and again they should all pass. Time to refactor. &lt;/li&gt;    &lt;li&gt;Now add a constant (readonly int) for the speed of light and then ensure the code in the shoot method refers to the constant ie:      &lt;br /&gt;private readonly int MAXVELOCITY = 300000000;       &lt;br /&gt;And       &lt;br /&gt;if (velocity &amp;gt; MAXVELOCITY)       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; return Tuple.Create(false, &amp;quot;Velocity of the cannon cannot travel faster than the speed of light&amp;quot;);       &lt;br /&gt;} &lt;/li&gt;    &lt;li&gt;Now build the project and have a look at the Test Impact View:      &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/S_za65ktgyI/AAAAAAAABNU/H5EvWML6HFs/s1600-h/clip_image013%5B4%5D.gif"&gt;&lt;img title="clip_image013" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="293" alt="clip_image013" src="http://lh5.ggpht.com/_iuwZHhydmEs/S_za74xd21I/AAAAAAAABNY/sZMVghA_Tmc/clip_image013_thumb%5B1%5D.gif?imgmax=800" width="534" border="0" /&gt;&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;This is very useful as we can see the impact of that change (even though its not a serious change) on the tests. If you want to run just the tests impacted by the change click on the Run Tests link in the Test Impact View window. While I won't talk further about the test impact view, it's worth using in your TDD activities. OK so this iteration is complete now for the calculation of the cannonball trajectory.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Iteration 5 - Shoot, the Messenger:Shot!!!&lt;/b&gt;     &lt;br /&gt;Time for the real fun of the shoot method. As the next four requirements are very close, I am going to include them in this iteration. Normally we would break these up but to keep this tutorial as brief as possible we'll group them together. They are:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Target Distance is simply the distance of the Cannon to Target, and is created randomly by default but can be overridden; &lt;/li&gt;    &lt;li&gt;Max distance for target is 20000 meters; &lt;/li&gt;    &lt;li&gt;Base the algorithm for the calculation of the cannons trajectory upon the following C# code (distance and height is meters and velocity is meters per second):      &lt;ul&gt;       &lt;li&gt;distance = velocity * Math.Cos(angleInRadians) * time; &lt;/li&gt;        &lt;li&gt;height = (velocity * Math.Sin(angleInRadians) * time) - (GRAVITY * Math.Pow(time, 2)) / 2; &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;A hit occurs if the cannon is within 50m of the target; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;First, we need a test to set a distance for the target and the correct angle and velocity for a miss (yes we are going to test for a miss first). Actually, for this functionality we are going to add two tests: one to test a miss and one for a hit.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;So lets add the tests: &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;[TestMethod]    &lt;br /&gt;public void TestCannonShootMiss()     &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; cannon.SetTarget(4000);     &lt;br /&gt;var shot = cannon.Shoot(45, 350);     &lt;br /&gt;Assert.IsTrue(shot.Item2 == &amp;quot;Missed cannonball landed at 12621 meters&amp;quot;);     &lt;br /&gt;}     &lt;br /&gt;[TestMethod]     &lt;br /&gt;public void TestCannonShootHit()     &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; cannon.SetTarget(12621);     &lt;br /&gt;var shot = cannon.Shoot(45, 350);     &lt;br /&gt;Assert.IsTrue(shot.Item2 == &amp;quot;Hit&amp;quot;);     &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;This will not compile so we can right click SetTarget and select Generate Method Stub. &lt;/li&gt;    &lt;li&gt;Run the tests and of course the last two tests fail &lt;/li&gt;    &lt;li&gt;We need to some changes to make it succeed, add this private variable and readonly int to the class: &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;private int distanceOfTarget;    &lt;br /&gt;private readonly double GRAVITY = 9.8;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;below the validation code replace      &lt;br /&gt;return Tuple.Create(true, &amp;quot;Angle OK&amp;quot;); //Not going to do //the calculation just yet       &lt;br /&gt;with:       &lt;br /&gt;string message;       &lt;br /&gt;bool hit;       &lt;br /&gt;int distanceOfShot = CalculateDistanceOfCannonShot(angle, velocity);       &lt;br /&gt;if (distanceOfShot == distanceOfTarget)       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; message = &amp;quot;Hit&amp;quot;;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; hit = true;       &lt;br /&gt;}       &lt;br /&gt;else       &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; message = String.Format(&amp;quot;Missed cannonball landed at {0} meters&amp;quot;, distanceOfShot);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; hit = false;       &lt;br /&gt;}       &lt;br /&gt;return Tuple.Create(hit, message); &lt;/li&gt;    &lt;li&gt;and then we create another method &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;public int CalculateDistanceOfCannonShot(int angle, int velocity)    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; int time = 0;     &lt;br /&gt;double height = 0;     &lt;br /&gt;double distance = 0;     &lt;br /&gt;double angleInRadians = (3.1415926536 / 180) * angle;     &lt;br /&gt;while (height &amp;gt;= 0)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; time++;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; distance = velocity * Math.Cos(angleInRadians) * time;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; height = (velocity * Math.Sin(angleInRadians) * time) - (GRAVITY * Math.Pow(time, 2)) / 2;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;return (int)distance;     &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Now Compile and run the tests and they will fail - because we are throwing an exception in SetTarget so lets change SetTarget to : &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;public void SetTarget(int distanceOfTarget)    &lt;br /&gt;{     &lt;br /&gt;this.distanceOfTarget = distanceOfTarget;     &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Run the tests again and now they all pass GREEN. Time to refactor. &lt;/li&gt;    &lt;li&gt;Lets add some code to the constructor of the cannon class to randomly set it &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;private Cannon()    &lt;br /&gt;{     &lt;br /&gt;//by default we setup a random target     &lt;br /&gt;Random r = new Random();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; SetTarget(r.Next(MAXDISTANCEOFTARGET));     &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;and a constant for MAXDISTANCEOFTARGET &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;private readonly int MAXDISTANCEOFTARGET = 20000;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Make sure DistanceOfTarget is now a property: &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;public int DistanceOfTarget    &lt;br /&gt;{     &lt;br /&gt;get { return distanceOfTarget; }     &lt;br /&gt;set { distanceOfTarget = value; }     &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;And now SetTarget can change to: &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;public void SetTarget(int distanceOfTarget)    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; if (!distanceOfTarget.Between(0, MAXDISTANCEOFTARGET))     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;throw new ApplicationException(String.Format(&amp;quot;Target distance must be between 1 and {0} meters&amp;quot;, MAXDISTANCEOFTARGET));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;this.distanceOfTarget = distanceOfTarget;     &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;And we need to include the burst radius code in the Shoot method which will replace: &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;if (distanceOfShot == distanceOfTarget)&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;With &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;if (distanceOfShot.WithinRange(this.distanceOfTarget, BURSTRADIUS))&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;and a couple of important changes here      &lt;ul&gt;       &lt;li&gt;We are using an extension method to provide a number of additional functions to ints. &lt;/li&gt;        &lt;li&gt;To add an extension method we follow the following steps:          &lt;ul&gt;           &lt;li&gt;Add a class to the console project &lt;/li&gt;            &lt;li&gt;Call it ExtensionMethods.cs &lt;/li&gt;            &lt;li&gt;Enter the following code: &lt;/li&gt;         &lt;/ul&gt;       &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;using System;    &lt;br /&gt;namespace System     &lt;br /&gt;{     &lt;br /&gt;public static class ExtensionMethods     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;public static bool Between(this int source, int min, int max)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;return (source &amp;gt;= min &amp;amp;&amp;amp; source &amp;lt;= max);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;public static bool WithinRange(this int source, int target, int offset)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;return (target.Between(source - offset, source + offset));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;ul&gt;     &lt;li&gt;We also need a BURSTRADIUS constant added to the class: &lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;private readonly int BURSTRADIUS = 50;&lt;/p&gt;  &lt;p&gt;The reason we use an extension method is because the Between and Within Range will be used often within the app. As we used the System namespace for these extension methods they will be provided always.    &lt;br /&gt;OK, So run the tests again and we find that they pass so time to move onto the next iteration     &lt;br /&gt;&lt;b&gt;Iteration 6 - Counting Shots not Crows.&lt;/b&gt;     &lt;br /&gt;So the last piece of functionality to test is the Number of Shots so lets start with a simple test.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;insert this after the last test. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;[TestMethod]    &lt;br /&gt;public void TestCannonCountShots()     &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; cannon.SetTarget(12621);     &lt;br /&gt;var shot = cannon.Shoot(45, 350);     &lt;br /&gt;Assert.IsTrue(shot.Item2 == &amp;quot;Hit - 1 Shot(s)&amp;quot;, &amp;quot;Number of shots:&amp;quot; + cannon.Shots);     &lt;br /&gt;}     &lt;br /&gt;This will not compile because Shots doesn't exist yet.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Right click on the Shots property and select Generate-&amp;gt;Property &lt;/li&gt;    &lt;li&gt;Run the tests again and you will see this fail so lets make some changes to Cannon including:      &lt;ul&gt;       &lt;li&gt;Change the property for Shots to: &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;public int Shots    &lt;br /&gt;{     &lt;br /&gt;get     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;return shots;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;ul&gt;     &lt;li&gt;Add a field to the class &lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;private int shots;&lt;/p&gt;  &lt;ul&gt;   &lt;ul&gt;     &lt;li&gt;Initialise the variable in the constructor. It should now look like: &lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;private Cannon()    &lt;br /&gt;{     &lt;br /&gt;//by default we setup a random target     &lt;br /&gt;Random r = new Random();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; SetTarget(r.Next((int)MAXDISTANCEOFTARGET));     &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;ul&gt;     &lt;li&gt;Increment the shot count in the shoot method - insert this after the validation for the speed of light:        &lt;br /&gt;shots ++; &lt;/li&gt;      &lt;li&gt;Change the message of the hit to:        &lt;br /&gt;message = String.Format(&amp;quot;Hit - {0} Shot(s)&amp;quot;, shots); &lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Run the tests again we see the following:      &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/S_za8p7GDDI/AAAAAAAABNc/LdulGe_uuK0/s1600-h/clip_image014%5B4%5D.gif"&gt;&lt;img title="clip_image014" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="155" alt="clip_image014" src="http://lh3.ggpht.com/_iuwZHhydmEs/S_zbbxgfv1I/AAAAAAAABNg/Q3iyU7Wl5nc/clip_image014_thumb1.gif?imgmax=800" width="532" border="0" /&gt;&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;This tells us the shot count is 3 not 1 (it also shows that the original test for a hit has to change to handle the new text) and the reason for this is the singleton pattern we are using. As we are only maintaining one instance of the object, that instance is actually being used for every Shoot that occurs during the run of tests. So we need to ensure every time we start a new game (ie. a new test) we reset the shot count. The easiest way is to introduce a Reset method where we can reset the shot count but also later on we can use this method for other things that need to be cleaned up/reset.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Add the following to Cannon.cs: &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;public void Reset()    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; shots = 0;     &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The way we can use this in our tests is by using a method that is being called before every test. Add the following method to CannonAttackTest &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;[TestInitialize]    &lt;br /&gt;public void ResetCannonObject()     &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160; cannon.Reset();     &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Let's change the original for test for the hit to: &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;[TestMethod]    &lt;br /&gt;public void TestCannonShootHit()     &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; cannon.SetTarget(12621);     &lt;br /&gt;var shot = cannon.Shoot(45, 350);     &lt;br /&gt;Assert.IsTrue(shot.Item2 == &amp;quot;Hit - 1 Shot(s)&amp;quot;);     &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Run the tests CTRL-F5. They will all pass:      &lt;br /&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/S_zbcsUDcYI/AAAAAAAABNk/Li6hgSyouhM/s1600-h/clip_image0154.gif"&gt;&lt;img title="clip_image015" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="241" alt="clip_image015" src="http://lh6.ggpht.com/_iuwZHhydmEs/S_zbdjh3IDI/AAAAAAAABNo/wghLVpzB0AE/clip_image015_thumb1.gif?imgmax=800" width="511" border="0" /&gt;&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;and the cannon class is pretty much done. This is the end of the 6th Iteration and the Classes are complete. We are now going to write the code for CannonAttack that will call the classes from the UI.    &lt;br /&gt;&lt;b&gt;Completing the Project&lt;/b&gt;     &lt;br /&gt;We can writethe Code in the Console UI to get the values from the user for the angle. This is important part because we haven't thought about UI till now, All the UI should be handled by the console. To do this:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Set the CannonAttack console project as the startup project &lt;/li&gt;    &lt;li&gt;Add the following code to the CannonAttack.cs file &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;using System;    &lt;br /&gt;namespace CannonAttack     &lt;br /&gt;{     &lt;br /&gt;class CannonAttack     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;private static readonly int MaxNumberOfShots = 50;     &lt;br /&gt;static void Main(string[] args)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;Console.WriteLine(&amp;quot;Welcome to CannonAttack&amp;quot;);     &lt;br /&gt;bool isStillPlaying = true;     &lt;br /&gt;while (isStillPlaying)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;bool isAHit = false;     &lt;br /&gt;Cannon cannon = Cannon.GetInstance();     &lt;br /&gt;while (!isAHit &amp;amp;&amp;amp; cannon.Shots &amp;lt; MaxNumberOfShots)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;int angle;     &lt;br /&gt;int velocity;     &lt;br /&gt;Console.WriteLine(String.Format(&amp;quot;Target is at {0} meters&amp;quot;, cannon.DistanceOfTarget));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; GetInputVariable(out angle, out velocity);     &lt;br /&gt;var shot = cannon.Shoot(angle, velocity);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; isAHit = shot.Item1;     &lt;br /&gt;Console.WriteLine(shot.Item2);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; isStillPlaying = GetIsPlayingAgain();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; cannon.Reset();     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;Console.WriteLine(&amp;quot;Thanks for playing Cannon Attack&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;}     &lt;br /&gt;This is the core of the application and it should provide the main basis for the cannon attack application.     &lt;br /&gt;Below are the additional helper methods that are needed, so add them in underneath the main method:&lt;/p&gt;  &lt;p&gt;private static bool GetIsPlayingAgain()    &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; bool isPlayingAgain = false;     &lt;br /&gt;bool validAnswer = false;     &lt;br /&gt;while (!validAnswer)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;Console.Write(&amp;quot;Do you want to play again (y/n)?&amp;quot;);     &lt;br /&gt;string playAgain = Console.ReadLine();     &lt;br /&gt;if (playAgain == &amp;quot;y&amp;quot; || playAgain == &amp;quot;Y&amp;quot;)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; isPlayingAgain = true;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; validAnswer = true;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;if (playAgain == &amp;quot;n&amp;quot; || playAgain == &amp;quot;N&amp;quot;)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; isPlayingAgain = false;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; validAnswer = true;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;return isPlayingAgain;     &lt;br /&gt;}     &lt;br /&gt;private static void GetInputVariable(out int angle, out int velocity)     &lt;br /&gt;{     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; string angleBuffer;     &lt;br /&gt;string velocityBuffer;     &lt;br /&gt;Console.Write(String.Format(&amp;quot;Enter Angle ({0}-{1}):&amp;quot;, Cannon.MINANGLE, Cannon.MAXANGLE));     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; angleBuffer = Console.ReadLine();     &lt;br /&gt;if (!int.TryParse(angleBuffer, out angle))     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;Console.WriteLine(&amp;quot;Not a number, defaulting to 45&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; angle = 45;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;Console.Write(&amp;quot;Enter Velocity (meters per second):&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; velocityBuffer = Console.ReadLine();     &lt;br /&gt;if (!int.TryParse(velocityBuffer, out velocity))     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {     &lt;br /&gt;Console.WriteLine(&amp;quot;Not a number, defaulting to 100 meters per second&amp;quot;);     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; velocity = 100;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;}     &lt;br /&gt;Now you should be able to run the application and it should work displaying the output similar to what we defined on page 2 and should look like:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/S_zbeKlagaI/AAAAAAAABNs/4Z8vTe1EgiM/s1600-h/clip_image0164.gif"&gt;&lt;img title="clip_image016" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="312" alt="clip_image016" src="http://lh3.ggpht.com/_iuwZHhydmEs/S_zbe3h7biI/AAAAAAAABNw/ho51H84GC0Q/clip_image016_thumb1.gif?imgmax=800" width="531" border="0" /&gt;&lt;/a&gt;     &lt;br /&gt;&lt;b&gt;&lt;i&gt;This is the End&lt;/i&gt;&lt;/b&gt;     &lt;br /&gt;That's it - your first TDD project is complete!!!. The next tutorial will introduce a number of new areas of functionality including:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Multiplayer; and &lt;/li&gt;    &lt;li&gt;Mountains. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Any feedback you have would be appreciated as I'll update this tutorial as needed.    &lt;br /&gt;&lt;b&gt;Additional Resources&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Head First Design Patterns, Freeman and Freeman, O'Reilly, 2004. &lt;/li&gt;    &lt;li&gt;Effective C# 50 Specific Ways to improve your C#, Bill Wagner, Addison -Wesley,2005. &lt;/li&gt;    &lt;li&gt;Trajectory Calculation Code: &lt;a href="http://forums.macrumors.com/showthread.php?t=180810"&gt;http://forums.macrumors.com/showthread.php?t=180810&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.mdsn.microsoft.com/"&gt;www.mdsn.microsoft.com&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-8965737149803516629?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/8965737149803516629/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2010/05/test-driven-development-tutorial-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/8965737149803516629'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/8965737149803516629'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2010/05/test-driven-development-tutorial-in-c.html' title='Test Driven Development Tutorial in C# 4.0'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_iuwZHhydmEs/S_zaHkIcTSI/AAAAAAAABLo/LjSyd4LnrNM/s72-c/clip_image001%5B5%5D.gif?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-1936691920176745384</id><published>2010-05-18T01:49:00.001-07:00</published><updated>2010-05-18T01:49:17.796-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Image Processing Lab in C#</title><content type='html'>&lt;p&gt; · &lt;a href="http://www.codeproject.com/KB/GDI-plus/Image_Processing_Lab/iplab_demo.zip"&gt;Download demo - 1025.2 KB&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;· &lt;a href="http://www.codeproject.com/KB/GDI-plus/Image_Processing_Lab/iplab_src.zip"&gt;Download source - 548.0 KB&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/S_JT7LIgxzI/AAAAAAAABJA/MiiuBFRExQs/s1600-h/clip_image001%5B4%5D.jpg"&gt;&lt;img title="clip_image001" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="325" alt="clip_image001" src="http://lh6.ggpht.com/_iuwZHhydmEs/S_JT74cQAaI/AAAAAAAABJE/lb4WMCZismw/clip_image001_thumb%5B1%5D.jpg?imgmax=800" width="461" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Image Processing Lab is a simple tool for image processing, which includes different filters and tools to analyze images available in the &lt;a href="http://code.google.com/p/aforge/"&gt;AForge.NET&lt;/a&gt; framework. It's easy to develop your own filters and to integrate them with the code or use the tools in your own application. The following filters are implemented in the &lt;a href="http://code.google.com/p/aforge/"&gt;AForge.NET&lt;/a&gt; framework and demonstrated in the application:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Color filters (grayscale, sepia, invert, rotate, channel extraction, channel replacing, channel filtering, color filtering, Euclidean color filtering); &lt;/li&gt;    &lt;li&gt;HSL filters (linear correction, brightness, contrast, saturation, hue modifier, HSL filtering); &lt;/li&gt;    &lt;li&gt;YCbCr filters (linear correction, YCbCr filtering, channel extraction/replacement); &lt;/li&gt;    &lt;li&gt;Binarization filters (threshold, threshold with carry, ordered dithering, Bayer dithering, Floyd-Steinberg, Burkes, Jarvis-Judice-Ninke, Sierra, Stevenson-Arce, Stucki dithering methods); &lt;/li&gt;    &lt;li&gt;Automatic binarization (simple image statistics); &lt;/li&gt;    &lt;li&gt;Mathematical morphology filters (erosion, dilatation, opening, closing, hit &amp;amp; miss, thinning, thickening); &lt;/li&gt;    &lt;li&gt;Convolution filters (mean, blur, sharpen, edges, Gaussian); &lt;/li&gt;    &lt;li&gt;2 Source filters (merge, intersect, add, subtract, difference, move towards, morph); &lt;/li&gt;    &lt;li&gt;Edge detectors (homogeneity, difference, sobel, canny); &lt;/li&gt;    &lt;li&gt;Blob counter, Connected components labeling; &lt;/li&gt;    &lt;li&gt;Pixellate, Simple skeletonization, Jitter, Shrink, Oil painting; &lt;/li&gt;    &lt;li&gt;Levels linear filter, gamma correction; &lt;/li&gt;    &lt;li&gt;Median filter, Adaptive smoothing, Conservative smoothing; &lt;/li&gt;    &lt;li&gt;Resize and Rotate; &lt;/li&gt;    &lt;li&gt;Texture generators based on Perlin noise; &lt;/li&gt;    &lt;li&gt;Texture filters (texturer, textured filtering, textured merging); &lt;/li&gt;    &lt;li&gt;Fourier transformation (lowpass and hipass filters). &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;You can create (save and load) your own convolution filters or filters based on standard mathematical morphology operators. Colorized grid makes it very convenient to work with custom convolution filters.&lt;/p&gt;  &lt;p&gt;A preview window allows you to view the results of changing filter parameters on the fly. You can scroll an image using the mouse in the preview area. All filters are applied only to the portion of the image currently viewed to speed up preview.&lt;/p&gt;  &lt;p&gt;A PhotoShop-like histogram allows you to get information about mean, standard deviation, median, minimum and maximum values.&lt;/p&gt;  &lt;p&gt;The program allows you to copy to or paste from clipboard, save and print images.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Using the Code&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Most filters are designed to work with 24bpp RGB images or with grayscale images. In the case of grayscale images, we use PixelFormat.Format8bppIndexed with color palette of 256 entries. To guarantee that your image is in one of the formats, you can use the following code:&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// load an image&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;System.Drawing.Bitmap image = (Bitmap) Bitmap.FromFile( fileName );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// format image&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;AForge.Imaging.Image.FormatImage( ref image );&lt;/p&gt;  &lt;p&gt;It is easy to apply any filter to your image:&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// load an image&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;System.Drawing.Bitmap image = (Bitmap) Bitmap.FromFile( fileName );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// create filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;AForge.Imaging.Filters.Median filter = new AForge.Imaging.Filters.Median( );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// apply filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;System.Drawing.Bitmap newImage = filter.Apply( image );&lt;/p&gt;  &lt;p&gt;Suppose, you want to apply a series of filters to an image. The straight way to do it is to apply filters one after another, but it's not very likely in the case of 3 or more filters. All filters implement the IFilter interface, so it allows us to create a collection of filters and apply it at once to an image (besides, the collection will also save us from disposing routines on intermediate images):&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// create filters sequence AForge.Imaging.Filters.FiltersSequence&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;filter = new AForge.Imaging.Filters.FiltersSequence( );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// add filters to the sequence&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;filter.Add( new AForge.Imaging.Filters.Sepia( ) );&lt;/p&gt;  &lt;p&gt;filter.Add( new AForge.Imaging.Filters.RotateBilinear( 45) );&lt;/p&gt;  &lt;p&gt;filter.Add( new AForge.Imaging.Filters.ResizeBilinear( 320, 240 ) );&lt;/p&gt;  &lt;p&gt;filter.Add( new AForge.Imaging.Filters.Pixellate( 8 ) );&lt;/p&gt;  &lt;p&gt;filter.Add( new AForge.Imaging.Filters.Jitter( 2 ) );&lt;/p&gt;  &lt;p&gt;filter.Add( new AForge.Imaging.Filters.Blur( ) );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// apply the sequence to an image&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;System.Drawing.Bitmap newImage = filter.Apply( image );&lt;/p&gt;  &lt;p&gt;It's easy to get such image statistics as mean, standard deviation, median, minimum and maximum values. It can be useful for image brightness/contrast regulation.&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// get image statistics&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;AForge.Imaging.ImageStatistics statistics =&lt;/p&gt;  &lt;p&gt;new AForge.Imaging.ImageStatistics( image );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// get the red histogram&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;AForge.Math.Histogram histogram = statistics.Red;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// get the values&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;double mean = histogram.Mean; &lt;i&gt;// mean red value&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;double stddev = histogram.StdDev; &lt;i&gt;// standard deviation of red values&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;int median = histogram.Median; &lt;i&gt;// median red value&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;int min = histogram.Min; &lt;i&gt;// min red value&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;int max = histogram.Max; &lt;i&gt;// max value&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// get 90% range around the median&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;AForge.IntRange range = histogram.GetRange( 0.9 );&lt;/p&gt;  &lt;p&gt;Image statistics can be easily combined with filters. Suppose that the minimum value of red is 50 on the image and the maximum value is 200. So, we can normalize the contrast of the red channel:&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// create levels filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;AForge.Imaging.Filters.LevelsLinear filter =&lt;/p&gt;  &lt;p&gt;new AForge.Imaging.Filters.LevelsLinear( );&lt;/p&gt;  &lt;p&gt;filter.InRed = new IntRange( histogram.Min, histogram.Max );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// apply the filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;System.Drawing.Bitmap newImage = filter.Apply( image );&lt;/p&gt;  &lt;p&gt;Or we can normalize the contrast of each channel, getting only the 90% ranges from each channel:&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// create levels filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;AForge.Imaging.Filters.LevelsLinear filter =&lt;/p&gt;  &lt;p&gt;new AForge.Imaging.Filters.LevelsLinear( );&lt;/p&gt;  &lt;p&gt;filter.InRed = statistics.Red.GetRange( 0.9 );&lt;/p&gt;  &lt;p&gt;filter.InGreen = statistics.Green.GetRange( 0.9 );&lt;/p&gt;  &lt;p&gt;filter.InBlue = statistics.Blue.GetRange( 0.9 );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// apply the filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;System.Drawing.Bitmap newImage = filter.Apply( image );&lt;/p&gt;  &lt;p&gt;&lt;b&gt;HSL Filters&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Using HSL color space is more obvious for some sorts of filters. For example, it's not very clean, how to adjust saturation levels of an image using RGB color space. But it can be done easily, using HSL color space:&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// create filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;AForge.Imaging.Filters.SaturationCorrection filter =&lt;/p&gt;  &lt;p&gt;new AForge.Imaging.Filters.SaturationCorrection( 0.1 );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// apply the filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;System.Drawing.Bitmap newImage = filter.Apply( image );    &lt;table cellspacing="0" cellpadding="0" border="1"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td width="50%"&gt;           &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/S_JT8THee0I/AAAAAAAABJI/2WqMDe60FNA/s1600-h/clip_image002%5B3%5D.jpg"&gt;&lt;img title="clip_image002" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="182" alt="clip_image002" src="http://lh6.ggpht.com/_iuwZHhydmEs/S_JT9Eb7h0I/AAAAAAAABJM/KrrKLANgo70/clip_image002_thumb.jpg?imgmax=800" width="244" border="0" /&gt;&lt;/a&gt;               &lt;br /&gt;Initial image&lt;/p&gt;         &lt;/td&gt;          &lt;td width="50%"&gt;           &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/S_JT-AuaaNI/AAAAAAAABJQ/XF7QUIwoNfE/s1600-h/clip_image003%5B3%5D.jpg"&gt;&lt;img title="clip_image003" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="182" alt="clip_image003" src="http://lh6.ggpht.com/_iuwZHhydmEs/S_JT_HLzdyI/AAAAAAAABJU/AD9yrGHFVGA/clip_image003_thumb.jpg?imgmax=800" width="244" border="0" /&gt;&lt;/a&gt;               &lt;br /&gt;Saturation adjusted&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;Using HSL color space, we can modify the hue value of pixels. Setting all hue values to the same value will lead to an image in gradations of one color:&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// create filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;AForge.Imaging.Filters.HueModifier filter =&lt;/p&gt;  &lt;p&gt;new AForge.Imaging.Filters.HueModifier( 142 );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// apply the filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;System.Drawing.Bitmap newImage = filter.Apply( image );&lt;/p&gt;  &lt;p&gt;It's possible to get much more interesting results using HSL filtering. For example, we can preserve only the specified range of hue values and desaturate all others out of the range. So, it will lead to a black and white image with only some regions colored.&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// create filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;AForge.Imaging.Filters.HSLFiltering filter =&lt;/p&gt;  &lt;p&gt;new AForge.Imaging.Filters.HSLFiltering( );&lt;/p&gt;  &lt;p&gt;filter.Hue = new IntRange( 340, 20 );&lt;/p&gt;  &lt;p&gt;filter.UpdateHue = false;&lt;/p&gt;  &lt;p&gt;filter.UpdateLuminance = false;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// apply the filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;System.Drawing.Bitmap newImage = filter.Apply( image );    &lt;table cellspacing="0" cellpadding="0" border="1"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td width="50%"&gt;           &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/S_JULqearcI/AAAAAAAABJY/TQclm6j9Ur0/s1600-h/clip_image0043.jpg"&gt;&lt;img title="clip_image004" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="182" alt="clip_image004" src="http://lh4.ggpht.com/_iuwZHhydmEs/S_JUMsyvZcI/AAAAAAAABJc/8NAiEl_il0Q/clip_image004_thumb.jpg?imgmax=800" width="244" border="0" /&gt;&lt;/a&gt;               &lt;br /&gt;Hue modified&lt;/p&gt;         &lt;/td&gt;          &lt;td width="50%"&gt;           &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/S_JUNEyCGmI/AAAAAAAABJg/wVPs5k8JjO8/s1600-h/clip_image0053.jpg"&gt;&lt;img title="clip_image005" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="182" alt="clip_image005" src="http://lh4.ggpht.com/_iuwZHhydmEs/S_JUNwy61yI/AAAAAAAABJk/F1gZ2_1qZOU/clip_image005_thumb.jpg?imgmax=800" width="244" border="0" /&gt;&lt;/a&gt;               &lt;br /&gt;HSL filtering&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Mathematical Morphology Filters&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;There are many tasks that can be accomplished using mathematical morphology filters. For example, we can reduce noise on binary images using erosion, or we can separate some objects with the filter. Using dilatation, we can grow some parts of our interest on the image. One of the most interesting morphological operators is known as Hit &amp;amp; Miss. All other morphological operators can be expressed from the Hit &amp;amp; Miss operator. For example, we can use it to search for particular structures on the image:&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// searching for vertical lines&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;short[,] vse = new short[3, 3] {&lt;/p&gt;  &lt;p&gt;{ 0, 1, 0 },&lt;/p&gt;  &lt;p&gt;{ 0, 1, 0 },&lt;/p&gt;  &lt;p&gt;{ 0, 1, 0 }&lt;/p&gt;  &lt;p&gt;};&lt;/p&gt;  &lt;p&gt;AForge.Imaging.Filters.HitAndMiss vFilter =&lt;/p&gt;  &lt;p&gt;new AForge.Imaging.Filters.HitAndMiss( vse );&lt;/p&gt;  &lt;p&gt;System.Drawing.Bitmap vImage = vFilter.Apply( image );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// searching for horizontal lines&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;short[,] hse = new short[3, 3] {&lt;/p&gt;  &lt;p&gt;{ 0, 0, 0 },&lt;/p&gt;  &lt;p&gt;{ 1, 1, 1 },&lt;/p&gt;  &lt;p&gt;{ 0, 0, 0 }&lt;/p&gt;  &lt;p&gt;};&lt;/p&gt;  &lt;p&gt;AForge.Imaging.Filters.HitAndMiss hFilter =&lt;/p&gt;  &lt;p&gt;new AForge.Imaging.Filters.HitAndMiss( hse );&lt;/p&gt;  &lt;p&gt;System.Drawing.Bitmap hImage = hFilter.Apply( image );    &lt;table cellspacing="0" cellpadding="0" border="1"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td&gt;           &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/S_JUOiz_jrI/AAAAAAAABJo/9r8J35SOqkI/s1600-h/clip_image0064.gif"&gt;&lt;img title="clip_image006" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="154" alt="clip_image006" src="http://lh6.ggpht.com/_iuwZHhydmEs/S_JUPFM3uWI/AAAAAAAABJs/RzXY_fbvnIw/clip_image006_thumb.gif?imgmax=800" width="154" border="0" /&gt;&lt;/a&gt;               &lt;br /&gt;Original image&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/S_JUPZH1R1I/AAAAAAAABJw/-qoa3nWRJJc/s1600-h/clip_image0073.gif"&gt;&lt;img title="clip_image007" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="154" alt="clip_image007" src="http://lh3.ggpht.com/_iuwZHhydmEs/S_JUQOagUwI/AAAAAAAABJ0/oyUt43pRD34/clip_image007_thumb.gif?imgmax=800" width="154" border="0" /&gt;&lt;/a&gt;               &lt;br /&gt;Searching for vertical lines&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/S_JUQ_BC2iI/AAAAAAAABJ4/iR-6jaEhmhE/s1600-h/clip_image0083.gif"&gt;&lt;img title="clip_image008" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="154" alt="clip_image008" src="http://lh3.ggpht.com/_iuwZHhydmEs/S_JURW93PkI/AAAAAAAABJ8/XaFi9HDlsMQ/clip_image008_thumb.gif?imgmax=800" width="154" border="0" /&gt;&lt;/a&gt;               &lt;br /&gt;Searching for horizontal lines&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;Using a thickening operator, we can grow some parts of the image in the places we need. For example, the next sample will lead to thickening horizontal lines in the bottom direction:&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// create filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;AForge.Imaging.Filters.FilterIterator filter =&lt;/p&gt;  &lt;p&gt;new AForge.Imaging.Filters.FilterIterator(&lt;/p&gt;  &lt;p&gt;new AForge.Imaging.Filters.HitAndMiss(&lt;/p&gt;  &lt;p&gt;new short [,] { { 1, 1, 1 }, { -1, 0, -1 }, { -1, -1, -1 } },&lt;/p&gt;  &lt;p&gt;HitAndMiss.Modes.Thinning ), 5 );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// apply the filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;System.Drawing.Bitmap newImage = filter.Apply( image );    &lt;table cellspacing="0" cellpadding="0" border="1"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td&gt;           &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/S_JURzmcsxI/AAAAAAAABKA/ORoO1QsTAdM/s1600-h/clip_image00612.gif"&gt;&lt;img title="clip_image006[1]" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="154" alt="clip_image006[1]" src="http://lh3.ggpht.com/_iuwZHhydmEs/S_JUSbhrrZI/AAAAAAAABKE/ovCgAI8qVZw/clip_image0061_thumb.gif?imgmax=800" width="154" border="0" /&gt;&lt;/a&gt;               &lt;br /&gt;Original image&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/S_JUS0zVupI/AAAAAAAABKI/vkIJu5IF-Ho/s1600-h/clip_image0093.gif"&gt;&lt;img title="clip_image009" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="154" alt="clip_image009" src="http://lh3.ggpht.com/_iuwZHhydmEs/S_JUTlQ2fpI/AAAAAAAABKM/ll1PQUpCc8M/clip_image009_thumb.gif?imgmax=800" width="154" border="0" /&gt;&lt;/a&gt;               &lt;br /&gt;Thickened image&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;Using a thinning operator, you can remove some unnecessary parts of the image. For example, you can develop a skeletonization filter with appropriate structuring elements:&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// create filter sequence&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;AForge.Imaging.Filters.FiltersSequence filterSequence =&lt;/p&gt;  &lt;p&gt;new AForge.Imaging.Filters.FiltersSequence( );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// add 8 thinning filters with different structuring elements&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;filterSequence.Add( new AForge.Imaging.Filters.HitAndMiss(&lt;/p&gt;  &lt;p&gt;new short [,] { { 0, 0, 0 }, { -1, 1, -1 }, { 1, 1, 1 } },&lt;/p&gt;  &lt;p&gt;HitAndMiss.Modes.Thinning ) );&lt;/p&gt;  &lt;p&gt;filterSequence.Add( new AForge.Imaging.Filters.HitAndMiss(&lt;/p&gt;  &lt;p&gt;new short [,] { { -1, 0, 0 }, { 1, 1, 0 }, { -1, 1, -1 } },&lt;/p&gt;  &lt;p&gt;HitAndMiss.Modes.Thinning ) );&lt;/p&gt;  &lt;p&gt;filterSequence.Add( new AForge.Imaging.Filters.HitAndMiss(&lt;/p&gt;  &lt;p&gt;new short [,] { { 1, -1, 0 }, { 1, 1, 0 }, { 1, -1, 0 } },&lt;/p&gt;  &lt;p&gt;HitAndMiss.Modes.Thinning ) );&lt;/p&gt;  &lt;p&gt;filterSequence.Add( new AForge.Imaging.Filters.HitAndMiss(&lt;/p&gt;  &lt;p&gt;new short [,] { { -1, 1, -1 }, { 1, 1, 0 }, { -1, 0, 0 } },&lt;/p&gt;  &lt;p&gt;HitAndMiss.Modes.Thinning ) );&lt;/p&gt;  &lt;p&gt;filterSequence.Add( new AForge.Imaging.Filters.HitAndMiss(&lt;/p&gt;  &lt;p&gt;new short [,] { { 1, 1, 1 }, { -1, 1, -1 }, { 0, 0, 0 } },&lt;/p&gt;  &lt;p&gt;HitAndMiss.Modes.Thinning ) );&lt;/p&gt;  &lt;p&gt;filterSequence.Add( new AForge.Imaging.Filters.HitAndMiss(&lt;/p&gt;  &lt;p&gt;new short [,] { { -1, 1, -1 }, { 0, 1, 1 }, { 0, 0, -1 } },&lt;/p&gt;  &lt;p&gt;HitAndMiss.Modes.Thinning ) );&lt;/p&gt;  &lt;p&gt;filterSequence.Add(new AForge.Imaging.Filters.HitAndMiss(&lt;/p&gt;  &lt;p&gt;new short [,] { { 0, -1, 1 }, { 0, 1, 1 }, { 0, -1, 1 } },&lt;/p&gt;  &lt;p&gt;HitAndMiss.Modes.Thinning ) );&lt;/p&gt;  &lt;p&gt;filterSequence.Add( new AForge.Imaging.Filters.HitAndMiss(&lt;/p&gt;  &lt;p&gt;new short [,] { { 0, 0, -1 }, { 0, 1, 1 }, { -1, 1, -1 } },&lt;/p&gt;  &lt;p&gt;HitAndMiss.Modes.Thinning ) );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// create filter iterator for 10 iterations&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;AForge.Imaging.Filters.FilterIterator filter =&lt;/p&gt;  &lt;p&gt;new AForge.Imaging.Filters.FilterIterator( filterSequence, 10 );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// apply the filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;System.Drawing.Bitmap newImage = filter.Apply( image );    &lt;table cellspacing="0" cellpadding="0" border="1"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td&gt;           &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/S_JUUEKdtHI/AAAAAAAABKQ/1zhK1TkFSaM/s1600-h/clip_image0103.gif"&gt;&lt;img title="clip_image010" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="154" alt="clip_image010" src="http://lh3.ggpht.com/_iuwZHhydmEs/S_JUUpO-RCI/AAAAAAAABKU/l79l3TIeOwE/clip_image010_thumb.gif?imgmax=800" width="154" border="0" /&gt;&lt;/a&gt;               &lt;br /&gt;Original image&lt;/p&gt;         &lt;/td&gt;          &lt;td&gt;           &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/S_JUVlZ0StI/AAAAAAAABKY/Z5jm40IS_cE/s1600-h/clip_image0113.gif"&gt;&lt;img title="clip_image011" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="154" alt="clip_image011" src="http://lh4.ggpht.com/_iuwZHhydmEs/S_JUWHgtRPI/AAAAAAAABKc/cAF1FP2pukA/clip_image011_thumb.gif?imgmax=800" width="154" border="0" /&gt;&lt;/a&gt;               &lt;br /&gt;Thinned image&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Fourier Transformation&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;It is easy to perform a Fourier transformation, which is useful for image analysis and filtering with the library:&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// create complex image from bitmap&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;AForge.Imaging.ComplexImage cimage =&lt;/p&gt;  &lt;p&gt;AForge.Imaging.ComplexImage.FromBitmap( bitmap );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// perform forward Fourier transformation&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;cimage.ForwardFourierTransform( );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// get frequency view&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;System.Drawing.Bitmap img = cimage.ToBitmap( );    &lt;table cellspacing="0" cellpadding="0" border="1"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td width="100%"&gt;           &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/S_JUWhpiYJI/AAAAAAAABKg/t3uEoTWZFu0/s1600-h/clip_image0123.jpg"&gt;&lt;img title="clip_image012" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="clip_image012" src="http://lh4.ggpht.com/_iuwZHhydmEs/S_JUXROIi1I/AAAAAAAABKk/_q4DDKCyOIQ/clip_image012_thumb.jpg?imgmax=800" width="244" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;Lowpass and hipass filtering can be performed using the FrequencyFilter method of the ComplexImage class:&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// lowpass filtering&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;cimage.FrequencyFilter( new Range( 0, 100 ) );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// perform backward Fourier transformation&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;cimage.BackwardFourierTransform( );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// get filtered image&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;System.Drawing.Bitmap img = cimage.ToBitmap( );&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Blob Counter&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Blob counter is a very useful feature and can be applied in many different applications. What does it do? It can count objects on a binary image and extract them. The idea comes from &amp;quot;Connected components labeling,&amp;quot; a filter that colors each separate object with a different color. Let's look into a small sample:&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// create filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;AForge.Imaging.Filters.ConnectedComponentsLabeling filter =&lt;/p&gt;  &lt;p&gt;new AForge.Imaging.Filters.ConnectedComponentsLabeling( );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// apply filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;System.Drawing.Bitmap newImage = filter.Apply( image );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// objects count&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;System.Diagnostics.Debug.WriteLine( &amp;quot;Objects count: &amp;quot; +&lt;/p&gt;  &lt;p&gt;filter.ObjectCount );&lt;/p&gt;  &lt;p&gt;Here are two images: initial image and colored image. So, it looks like the filter is really able to count objects.    &lt;table cellspacing="0" cellpadding="0" border="1"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td width="50%"&gt;           &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/S_JUX8_jFKI/AAAAAAAABKo/isnfs-vaFU8/s1600-h/clip_image0133.gif"&gt;&lt;img title="clip_image013" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="144" alt="clip_image013" src="http://lh6.ggpht.com/_iuwZHhydmEs/S_JUYecKnII/AAAAAAAABKs/O6_d9cXqfmA/clip_image013_thumb.gif?imgmax=800" width="204" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td width="50%"&gt;           &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/S_JUZImT-qI/AAAAAAAABKw/OlZ-o3MphF4/s1600-h/clip_image0143.gif"&gt;&lt;img title="clip_image014" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="144" alt="clip_image014" src="http://lh3.ggpht.com/_iuwZHhydmEs/S_JUZbJX2ZI/AAAAAAAABK0/1cV0QhwXj6M/clip_image014_thumb.gif?imgmax=800" width="204" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;Here is another example of objects counting and retrieving their position and size:&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// process an image&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;AForge.Imaging.BlobCounter blobCounter = new BlobCounter( image );&lt;/p&gt;  &lt;p&gt;Rectangle[] rects = blobCounter.GetObjectRectangles( );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// objects count&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;System.Diagnostics.Debug.WriteLine( &amp;quot;Objects count: &amp;quot; + rects.Length );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// objects dimension&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;foreach ( Rectangle rc in rects )&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;System.Diagnostics.Debug.WriteLine(&lt;/p&gt;  &lt;p&gt;string.Format(&amp;quot;Position: ({0}, {1}), Size: {2} x {3}&amp;quot;,&lt;/p&gt;  &lt;p&gt;rc.Left, rc.Top, rc.Width, rc.Height ) );&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;It's possible to extract each object with the GetObjects method of BlobCounter:&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// process an image&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;AForge.Imaging.BlobCounter blobCounter = new BlobCounter( image );&lt;/p&gt;  &lt;p&gt;Blob[] blobs = blobCounter.GetObjects( image );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// process blobs&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;foreach ( Blob blob in blobs )&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// ...&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// blob.Location - location of the blob&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// blob.Image - blob`s image&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&lt;b&gt;YCbCr Filtering&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;YCbCr filters are provided with similar functionality to RGB and HSL filters. The YCbCr linear correction filter performs as its analogues from other color spaces, but operates with the Y, Cb and Cr components respectively, providing us with additional convenient ways of color correction. The next small sample demonstrates the use of the YCbCr linear filter and the use of in-place filtering: the feature, which allows you to filter a source image instead of creating a new result image, is as follows:&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// create filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;YCbCrLinear filter = new YCbCrLinear( );&lt;/p&gt;  &lt;p&gt;filter.InCb = new DoubleRange( -0.276, 0.163 );&lt;/p&gt;  &lt;p&gt;filter.InCr = new DoubleRange( -0.202, 0.500 );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// apply filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;filter.ApplyInPlace( image );    &lt;table cellspacing="0" cellpadding="0" border="1"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td width="50%"&gt;           &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/S_JUaO8SLOI/AAAAAAAABK4/D0x3I9q9KYM/s1600-h/clip_image0153.jpg"&gt;&lt;img title="clip_image015" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="184" alt="clip_image015" src="http://lh5.ggpht.com/_iuwZHhydmEs/S_JUbCz-ZnI/AAAAAAAABK8/HIFFRrmz6Gk/clip_image015_thumb.jpg?imgmax=800" width="244" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td width="50%"&gt;           &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/S_JUbscCYJI/AAAAAAAABLA/XWEULc-N0WY/s1600-h/clip_image0163.jpg"&gt;&lt;img title="clip_image016" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="184" alt="clip_image016" src="http://lh4.ggpht.com/_iuwZHhydmEs/S_JUcXqQ01I/AAAAAAAABLE/yiyK0v3HdjQ/clip_image016_thumb.jpg?imgmax=800" width="244" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Perlin Noise Filters&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.animeimaging.com/asp/PerlinNoise.aspx"&gt;Perlin noise&lt;/a&gt; has many applications and one of the most interesting of them is the creation of different effects, like marble, wood, clouds, etc. Application of such effects to images can be done in two steps. The first step is to generate effect textures and the second step is to apply the textures to the particular image. Texture generators are placed into the Texturesnamespace of the library, which contains generators for such effects as clouds, wood, marble, labyrinth and textile. All these texture generators implement the ITextureGeneratorinterface. For applying textures to images, there are three filters. The fist one, Texturer, is for texturing images. The second, TexturedFilter, allows application of any other filter to an image using the texture as a mask. The third, TexturedMerge, allows merging of two images using the texture as a mask.&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// 1 - Marble effect&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// create texture&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;ITextureGenerator generator = new MarbleTexture( );&lt;/p&gt;  &lt;p&gt;float[,] texture = generator.Generate( image.Width, image.Height );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// create filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;IFilter filter1 = new Texturer( texture );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// apply filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;Bitmap newImage1 = filter1.Apply( image );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// 2 - Wood effect&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// create filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;IFilter filter2 = new Texturer( new WoodTexture( ) );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// apply filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;Bitmap newImage2 = filter2.Apply( image );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// 3 - Textile effect&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// create filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;IFilter filter3 = new Texturer( new TextileTexture( ) );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// apply filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;Bitmap newImage3 = filter3.Apply( image );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// 4 - Rusty effect&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;IFilter filter4 = new TexturedFilter( new CloudsTexture( ),&lt;/p&gt;  &lt;p&gt;new Sepia( ) , new GrayscaleBT709( ) );&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// apply filter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;Bitmap newImage4 = filter4.Apply( image );    &lt;table cellspacing="0" cellpadding="0" border="1"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td width="50%"&gt;           &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/S_JUdY-zXwI/AAAAAAAABLI/8R6Dw4sWyEU/s1600-h/clip_image0173.jpg"&gt;&lt;img title="clip_image017" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="184" alt="clip_image017" src="http://lh5.ggpht.com/_iuwZHhydmEs/S_JUd4Orc8I/AAAAAAAABLM/jF3Wt8AHZkQ/clip_image017_thumb.jpg?imgmax=800" width="244" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td width="50%"&gt;           &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/S_JUeiKmSTI/AAAAAAAABLQ/IkDbADjXZQc/s1600-h/clip_image0183.jpg"&gt;&lt;img title="clip_image018" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="184" alt="clip_image018" src="http://lh3.ggpht.com/_iuwZHhydmEs/S_JUfWQ7E7I/AAAAAAAABLU/9JIuRY8Is84/clip_image018_thumb.jpg?imgmax=800" width="244" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;        &lt;tr&gt;         &lt;td width="50%"&gt;           &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/S_JUgb_PWJI/AAAAAAAABLY/3ZeytDwGrDQ/s1600-h/clip_image0193.jpg"&gt;&lt;img title="clip_image019" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="184" alt="clip_image019" src="http://lh4.ggpht.com/_iuwZHhydmEs/S_JUgykuhbI/AAAAAAAABLc/3SZL4_rUBKU/clip_image019_thumb.jpg?imgmax=800" width="244" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;         &lt;/td&gt;          &lt;td width="50%"&gt;           &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/S_JUhmuVvqI/AAAAAAAABLg/-NgFqbSwNRA/s1600-h/clip_image0203.jpg"&gt;&lt;img title="clip_image020" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="184" alt="clip_image020" src="http://lh4.ggpht.com/_iuwZHhydmEs/S_JUiU_MlbI/AAAAAAAABLk/4vZvS6Pca9U/clip_image020_thumb.jpg?imgmax=800" width="244" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;         &lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;&lt;b&gt;AForge.NET Framework&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The Image Processing Lab application is based on the &lt;a href="http://code.google.com/p/aforge/"&gt;AForge.NET&lt;/a&gt; framework, which provides all the filters and image processing routines available in the application. To get more information about the framework, you may read the &lt;a href="http://www.codeproject.com/cs/algorithms/aforge.asp"&gt;dedicated article&lt;/a&gt; on The Code Project or visit the &lt;a href="http://code.google.com/p/aforge/"&gt;project's home page&lt;/a&gt;, where you can get all the latest information about it, participate in a discussion group or submit issues or requests for enhancements.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;I suppose the code may be interesting for someone who would like to start studying image processing or for filters/effects developers. As for me, I'll use the tool for my further research in computer vision. Besides, the library helped me very much in successfully finishing my bachelor work.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;History&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;[08.03.2007] - Version 2.4.0      &lt;ul&gt;       &lt;li&gt;Application converted to .NET 2.0; &lt;/li&gt;        &lt;li&gt;Integrated with AForge.NET framework. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;[13.06.2006] - Version 2.3.0      &lt;ul&gt;       &lt;li&gt;In place filter interface introduced, which allows filter application on the source image; &lt;/li&gt;        &lt;li&gt;Perlin noise texture generators (marble, wood, textile, labyrinth, clouds); &lt;/li&gt;        &lt;li&gt;Texture filters (texturer, textured filtering, textured merging); &lt;/li&gt;        &lt;li&gt;RGB to YCbCr and YCbCr to TGB converters; &lt;/li&gt;        &lt;li&gt;YCbCr filters; &lt;/li&gt;        &lt;li&gt;Image statistics for YCbCr; &lt;/li&gt;        &lt;li&gt;Other minor changes (fix of Canny edge detector, Pixellate filter updated, morph filter). &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;[20.09.2005] - Version 2.2.0      &lt;ul&gt;       &lt;li&gt;Canny edge detector; &lt;/li&gt;        &lt;li&gt;Oil painting, Conservative smoothing; &lt;/li&gt;        &lt;li&gt;Simple image statistics threshold. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;[20.08.2005] - Version 2.1.0      &lt;ul&gt;       &lt;li&gt;Blob counter, Connected components labeling; &lt;/li&gt;        &lt;li&gt;Sobel edge detector; &lt;/li&gt;        &lt;li&gt;Adaptive smoothing, Gaussian blur, Image cropping. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;[12.07.2005] - Version 2.0.0      &lt;ul&gt;       &lt;li&gt;Homogeneity and Difference edge detectors; &lt;/li&gt;        &lt;li&gt;Fourier transformation (lowpass and hipass filters); &lt;/li&gt;        &lt;li&gt;AForge namespace; &lt;/li&gt;        &lt;li&gt;Copy and Paste to clipboard; &lt;/li&gt;        &lt;li&gt;Image saving and printing. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;[20.06.2005] - Version 1.4.0      &lt;ul&gt;       &lt;li&gt;More morphological methods (hit &amp;amp; miss, thinning, thickening); &lt;/li&gt;        &lt;li&gt;HSL filters; &lt;/li&gt;        &lt;li&gt;Gamma correction, filter iterator, etc. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;[29.03.2005] - Version 1.3.0      &lt;ul&gt;       &lt;li&gt;Resize and rotate; &lt;/li&gt;        &lt;li&gt;Jitter, Shrink, more dithering methods; &lt;/li&gt;        &lt;li&gt;MaskedFilter. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;[20.03.2005] - Version 1.2.0      &lt;ul&gt;       &lt;li&gt;More filters; &lt;/li&gt;        &lt;li&gt;Preview window; &lt;/li&gt;        &lt;li&gt;Grid colorization for morphology and convolution custom filters; &lt;/li&gt;        &lt;li&gt;Support for two source filters; &lt;/li&gt;        &lt;li&gt;Toolbar. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;[03.03.2005] - Version 1.0.0 &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;URL&amp;quot;: &lt;a href="http://www.codeproject.com/KB/GDI-plus/Image_Processing_Lab.aspx?display=Print"&gt;http://www.codeproject.com/KB/GDI-plus/Image_Processing_Lab.aspx?display=Print&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-1936691920176745384?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/1936691920176745384/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2010/05/image-processing-lab-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/1936691920176745384'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/1936691920176745384'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2010/05/image-processing-lab-in-c.html' title='Image Processing Lab in C#'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_iuwZHhydmEs/S_JT74cQAaI/AAAAAAAABJE/lb4WMCZismw/s72-c/clip_image001_thumb%5B1%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-6470872646309986094</id><published>2010-05-18T01:29:00.000-07:00</published><updated>2010-05-18T01:31:26.125-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Technology News'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Cutting-Edge Tech'/><title type='text'>Dynamic Type in C# 4.0</title><content type='html'>&lt;p&gt;Dynamic is a new type introduced in c# 4.0.Dynamic types are declared with the dynamic keyword. The objects of type Dynamic are not type checked at compile time. It behaves like type Object in most cases .Object of any type can be assigned to a variable of Dynamic type .Variable of Dynamic type can get its value even from HTML Document Object Model (DOM) or COM API. If the code is not valid, errors are caught at run time not at compile time.&lt;/p&gt;  &lt;p&gt;C# was until now a statically bound language. This means that if the compiler couldn't find the method for an object to bind to then it will throw compilation error.&lt;/p&gt;  &lt;p&gt;We declare at compile-time the type to be dynamic, but at run-time we get a strongly typed object.&lt;/p&gt;  &lt;p&gt;Dynamic objects expose members such as properties and methods at run time, instead of compile time. If you try to access members of a Dynamic type in &lt;a href="http://www.c-sharpcorner.com/UploadFile/ashish_2008/1157/"&gt;visual studio&lt;img title="clip_image001" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="10" alt="clip_image001" src="http://lh5.ggpht.com/_iuwZHhydmEs/S_JQTdCFtZI/AAAAAAAABIo/RaAql88_-iE/clip_image001%5B4%5D.gif?imgmax=800" width="10" border="0" /&gt;&lt;/a&gt; IDE you will get the message &amp;quot;The operation will be resolved at runtime&amp;quot;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/S_JQUE4KBfI/AAAAAAAABIs/-w-8tYx1Vbw/s1600-h/clip_image002%5B4%5D.gif"&gt;&lt;img title="clip_image002" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="365" alt="clip_image002" src="http://lh5.ggpht.com/_iuwZHhydmEs/S_JQU0wXCkI/AAAAAAAABIw/-3sznxDd9PI/clip_image002_thumb%5B1%5D.gif?imgmax=800" width="539" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Difference between Object, Var and Dynamic type&lt;/p&gt;  &lt;p&gt;If we execute the following code &lt;/p&gt;  &lt;p&gt;dynamic dyn = 0;&lt;/p&gt;  &lt;p&gt;object obj = 0;&lt;/p&gt;  &lt;p&gt;var var = 0;&lt;/p&gt;  &lt;p&gt;System.Console.WriteLine(dyn.GetType());&lt;/p&gt;  &lt;p&gt;System.Console.WriteLine(obj.GetType());&lt;/p&gt;  &lt;p&gt;System.Console.WriteLine(var.GetType());&lt;/p&gt;  &lt;p&gt;We will get the runtime types of all the Object ,Dynamic and var variables as Sytem.Int32 .But the type of var variable is available at compile time as well.&lt;/p&gt;  &lt;p&gt;But now if we add the following two statements the second statement will give compile time error&amp;#160; because the expression is type checked at compile time while the first statement compiles successfully because expressions of dynamic type are not type checked at compile time and the var type variable is assigned the appropriate datatype at compile time itself.&lt;/p&gt;  &lt;p&gt;dyn = dyn + 1;&lt;/p&gt;  &lt;p&gt;obj = obj + 1;&lt;/p&gt;  &lt;p&gt;var = var + 1;&lt;/p&gt;  &lt;p&gt;If we execute the below program&lt;/p&gt;  &lt;p&gt;class Dynamic&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;static void Main(string[] args)&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;  &lt;p&gt;dynamic dyn;&lt;/p&gt;  &lt;p&gt;string str = &amp;quot;Dynamic type test.String&amp;quot;;&lt;/p&gt;  &lt;p&gt;StringBuilder sb = new StringBuilder();&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; sb.Append(&amp;quot;Dynamic type test.StringBuilder&amp;quot;);&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; dyn = str;&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DynamicFunction(dyn);//This will call the first function because at run time the dynamic type is of string type&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; dyn = sb;&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DynamicFunction(dyn);////This will call the first function because at run time the dynamic type is of string builder type&lt;/p&gt;  &lt;p&gt;Console.Read();&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;public static void DynamicFunction(string s)&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;  &lt;p&gt;Console.WriteLine(s);&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;public static void DynamicFunction(StringBuilder sb)&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;  &lt;p&gt;Console.WriteLine(sb.ToString());&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;We will get the output as shown below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/S_JQVpubMfI/AAAAAAAABI0/zYBpUAPlacc/s1600-h/clip_image003%5B5%5D.gif"&gt;&lt;img title="clip_image003" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="272" alt="clip_image003" src="http://lh5.ggpht.com/_iuwZHhydmEs/S_JQWf0FfDI/AAAAAAAABI4/iWL4vBVJg7c/clip_image003_thumb%5B2%5D.gif?imgmax=800" width="537" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;To conclude Dynamic Type is a nice feature when it comes to interoperatibility and .NET usage with other Dynamic languages. However Dynamic type also makes it the responsibility of the &lt;a href="http://www.c-sharpcorner.com/UploadFile/ashish_2008/1157/"&gt;developer&lt;img title="clip_image001[1]" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="10" alt="clip_image001[1]" src="http://lh5.ggpht.com/_iuwZHhydmEs/S_JQXL5CvDI/AAAAAAAABI8/9bEkGi4NCUE/clip_image001%5B1%5D%5B2%5D.gif?imgmax=800" width="10" border="0" /&gt;&lt;/a&gt; for the correct usage of the calls.&lt;/p&gt;  &lt;p&gt;URL: &lt;a href="http://www.c-sharpcorner.com/UploadFile/ashish_2008/1157/"&gt;http://www.c-sharpcorner.com/UploadFile/ashish_2008/1157/&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-6470872646309986094?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/6470872646309986094/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2010/05/dynamic-type-in-c-40.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/6470872646309986094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/6470872646309986094'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2010/05/dynamic-type-in-c-40.html' title='Dynamic Type in C# 4.0'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_iuwZHhydmEs/S_JQTdCFtZI/AAAAAAAABIo/RaAql88_-iE/s72-c/clip_image001%5B4%5D.gif?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-4172302388728067648</id><published>2009-10-25T05:09:00.001-07:00</published><updated>2009-10-25T05:09:21.591-07:00</updated><title type='text'>Developing and Deploying Custom Web Parts for SharePoint Portal 2007</title><content type='html'>&lt;table border="0" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td&gt;&amp;#160;&lt;/td&gt;        &lt;td width="10"&gt;&amp;#160;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top"&gt;         &lt;table border="0" cellspacing="0" cellpadding="0"&gt;&lt;tbody&gt;             &lt;tr&gt;               &lt;td valign="top"&gt;                 &lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;/p&gt;                  &lt;p&gt;&lt;b&gt;&lt;u&gt;Overview and difference with SPS 2003:&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;                  &lt;p&gt;Developing Web Part for SharePoint Portal 2007 is different as compared to developing for SPS 2003. Web Parts Developed in .Net 1.1 for SPS 2003 used the &lt;b&gt;SharePoint.WebPartPages&lt;/b&gt; namespace, however the Web Part in ASP.Net 2.0 is found under the&lt;b&gt;System.Web.UI.WebControls.WebParts.&lt;/b&gt;&lt;/p&gt;                  &lt;p&gt;&lt;b&gt;&lt;u&gt;Development of Web Part in VS 2005&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;                  &lt;p&gt;To Get Started with creating Custom Web Part for MOSS 2007 in Microsoft Visual Studio 2005, Open the IDE and create a new C# project, Select Class Library as Project Type. Name It as &lt;i&gt;NewWebPart.&lt;/i&gt;&lt;/p&gt;                  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SuQ_kGjlW4I/AAAAAAAABG8/T53tg3Qtj3Y/s1600-h/clip_image001%5B5%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image001" border="0" alt="clip_image001" src="http://lh6.ggpht.com/_iuwZHhydmEs/SuQ_lNwN9DI/AAAAAAAABHA/-DcMbuQ95nI/clip_image001_thumb%5B2%5D.jpg?imgmax=800" width="635" height="341" /&gt;&lt;/a&gt;&lt;/p&gt;                  &lt;p&gt;Add a reference to the System.Web&amp;#160; from .Net components into the project. The System.Web dll contains the required namespace of&lt;b&gt;System.Web.UI.WebControls.WebParts&lt;/b&gt; .&lt;/p&gt;                  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SuQ_l_Kb8CI/AAAAAAAABHE/_lW6MZRfDGY/s1600-h/clip_image002%5B5%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://lh3.ggpht.com/_iuwZHhydmEs/SuQ_m7knByI/AAAAAAAABHI/SaXIs0SdzoQ/clip_image002_thumb%5B2%5D.jpg?imgmax=800" width="621" height="371" /&gt;&lt;/a&gt;&lt;/p&gt;                  &lt;p&gt;In The Project explorer view rename the Class1.cs with NewWbPart.cs to be consistent with this example; this will result in renaming the Class name as well. With the help of “using” keyword include the namespaces as shown in the code example below. Derive / Extend the NewWebPart Class from the WebPart Class ( System.Web.UI.WebControls.WebParts.WebPart), and add the code as shown below. The CreateChildren Control is same as in .Net 1.1, that it would create and add controls to this Web Part Class,. In this case I have only added a WebControl.Calender Object. The RenderControl Method is an override for the WebPart Base Class and calls the RenderChildren Method, this causes the Children Controls to be rendered on the Particular HtmlTextWriter passed as a parameter to the method.&lt;/p&gt;                  &lt;hr align="left" size="1" width="100%" noshade="noshade" /&gt;                  &lt;p&gt;using System;&lt;/p&gt;                  &lt;p&gt;using System.Collections.Generic;&lt;/p&gt;                  &lt;p&gt;using System.Text;&lt;/p&gt;                  &lt;p&gt;using System.Web;&lt;/p&gt;                  &lt;p&gt;using System.Web.UI;&lt;/p&gt;                  &lt;p&gt;using System.Web.UI.WebControls;&lt;/p&gt;                  &lt;p&gt;using System.Web.UI.WebControls.WebParts;&lt;/p&gt;                  &lt;p&gt;namespace NewWepPart&lt;/p&gt;                  &lt;p&gt;{&lt;/p&gt;                  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; public class NewWebPart : WebPart&lt;/p&gt;                  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;                  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; protected override void CreateChildControls()&lt;/p&gt;                  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;                  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Calendar cldr = new Calendar();&lt;/p&gt;                  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; cldr.Enabled = true;&lt;/p&gt;                  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; cldr.ShowGridLines = true;&lt;/p&gt;                  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; cldr.ShowTitle = true;&lt;/p&gt;                  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; cldr.EnableViewState = true;&lt;/p&gt;                  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; cldr.SelectedDate = DateTime.Now;&lt;/p&gt;                  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Controls.Add(cldr);&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; �&lt;/p&gt;                  &lt;p&gt;�&lt;/p&gt;                  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;                  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; public override void RenderControl(HtmlTextWriter writer)&lt;/p&gt;                  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;                  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; RenderChildren(writer);&lt;/p&gt;                  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;                  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;                  &lt;p&gt;}&lt;/p&gt;                  &lt;hr align="left" size="1" width="100%" noshade="noshade" /&gt;                  &lt;p&gt;Build the project and on successful built you are ready to Deploy the Web Part to the Portal Site.&lt;/p&gt;                  &lt;p&gt;&lt;b&gt;&lt;u&gt;Deployment of Web Part:&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;                  &lt;p&gt;In order to deploy a web part to a SharePoint portal 2007 site, we must have the URL of the site to which we want our web part needs to be deployed (displayed in fact). As it&amp;#160; is mentioned earlier that the Web Parts developed in .Net 2.0 environment does have a .CAB project , instead an assembly is created on build of project. Now there are two choices to deploy the assembly to the SharePoint portal directory.&lt;/p&gt;                  &lt;ul&gt;                   &lt;li&gt;Deploy the assembly to the Assembly Folder (GAC) (requires the assembly to be stron named).&lt;/li&gt;                    &lt;li&gt;Put the assembly to the bin folder of the portal directory.&lt;/li&gt;                 &lt;/ul&gt;                  &lt;p&gt;For the sake of simplicity, the later choice is being demonstrated in this example.&lt;/p&gt;                  &lt;p&gt;&lt;u&gt;                     &lt;br /&gt;&lt;/u&gt;&lt;/p&gt;                  &lt;p&gt;&lt;b&gt;&lt;u&gt;Putting Assembly in Bin Folder:&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;                  &lt;p&gt;The MOSS 2007 creates every portal in the inetpub\wwwroot\wss folder. The easiest way to find the bin folder from these folder hierarchies is to go from &lt;b&gt;&lt;i&gt;inetmgr&lt;/i&gt;&lt;/b&gt; console. Locate the appropriate portal (for which u want to deploy the web part), identified with the port number. Right click and have &lt;b&gt;Properties&lt;/b&gt;. Under the &lt;b&gt;Home Directory&lt;/b&gt; Tab, note the path in &lt;b&gt;Local path&lt;/b&gt; text box. Verify if the bin folder exists in the specified path by opening it in browser. If the folder doesn’t exist then create one. Now copy the assembly form the project output folder and paste it in bin folder of portal.&lt;/p&gt;                  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SuQ_nw9OZXI/AAAAAAAABHM/Q_x4yTTxLCI/s1600-h/clip_image004%5B5%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://lh4.ggpht.com/_iuwZHhydmEs/SuQ_o_40MQI/AAAAAAAABHQ/7SqszJ23wPk/clip_image004_thumb%5B2%5D.jpg?imgmax=800" width="521" height="414" /&gt;&lt;/a&gt;&lt;/p&gt;                  &lt;p&gt;However there is another work around for putting the assembly in to the portal’s bin folder again ad again each time the Web Part Project is built with changes.&lt;/p&gt;                  &lt;p&gt;&lt;b&gt;Right click&lt;/b&gt; on the project name (&lt;b&gt;NewWebPart&lt;/b&gt;) in the VS.Net 2005 IDE and click &lt;b&gt;properties&lt;/b&gt;. Under&amp;#160; the &lt;b&gt;Build&lt;/b&gt; page paste the same path copied from &lt;b&gt;&lt;i&gt;inetmgr&lt;/i&gt;&lt;/b&gt; console into the &lt;b&gt;Output Path. &lt;/b&gt;As shown in figure below. This will result in the latest assembly automatically deployed to the bin folder every time the project is built.&lt;/p&gt;                  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SuQ_pn-cNVI/AAAAAAAABHU/mr_JYAT17LU/s1600-h/clip_image006%5B5%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://lh6.ggpht.com/_iuwZHhydmEs/SuQ_qqMXpiI/AAAAAAAABHY/jMnmeoP18Lc/clip_image006_thumb%5B2%5D.jpg?imgmax=800" width="584" height="371" /&gt;&lt;/a&gt;&lt;/p&gt;                  &lt;p&gt;&lt;b&gt;&lt;u&gt;Adding the Safe Control Entry:&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;                  &lt;p&gt;Even though the assembly is present in the Portal’s Bin folder, there is another step required to make the Control (Web Part) assembly usable on the Portal Pages. Since the control will need to render on multiple machines in different browsers with as many user accounts as the organizations have. There is a need to declare the control as “safe”. To do so open the web.config file placed under the portal’s directory in the VS.Net 2005 IDE.&lt;/p&gt;                  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SuQ_rQHcLfI/AAAAAAAABHc/FCX1gyMxJj4/s1600-h/clip_image008%5B5%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://lh4.ggpht.com/_iuwZHhydmEs/SuQ_sewOCTI/AAAAAAAABHg/Fe6pbz_-Gw4/clip_image008_thumb%5B2%5D.jpg?imgmax=800" width="589" height="395" /&gt;&lt;/a&gt;&lt;/p&gt;                  &lt;p&gt;Then edit the file in the section of SafeControls, create a new SafeControl entry for our assembly as shown below. Save the file and close it.&lt;/p&gt;                  &lt;p&gt;&amp;lt;SafeControls&amp;gt;&lt;/p&gt;                  &lt;p&gt;.&lt;/p&gt;                  &lt;p&gt;.&lt;/p&gt;                  &lt;p&gt;.&lt;/p&gt;                  &lt;p&gt;&amp;lt;SafeControl Assembly=&amp;quot;NewWebPart&amp;quot; Namespace=&amp;quot;NewWebPart&amp;quot; TypeName=&amp;quot;*&amp;quot; Safe=&amp;quot;True&amp;quot; /&amp;gt;&lt;/p&gt;                  &lt;p&gt;SafeControls&amp;gt;&lt;/p&gt;                  &lt;p&gt;&lt;b&gt;&lt;u&gt;Configuring Portal to use NewWebPart&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;                  &lt;p&gt;Since now the web part have been written and deployed to the desired portal’s directory. The next task is to use the web part on the Portal’s Site. The Web Part Deployed to the portal can be placed on any site within that Portal. For convenience this NewWebPart is demonstrated to be placed on the home page of default Portal.&lt;/p&gt;                  &lt;p&gt;Open the portal site in the internet explorer; in this case &lt;a href="http://oss1/"&gt;http://oss1&lt;/a&gt; is the URL for the default portal, ensuring that the current logged in user has the administrative rights on the portal site.&lt;/p&gt;                  &lt;p&gt;To begin with, the first step is to add the newly deployed web to the Portal’s web part gallery, since the portal is using the configuration databases to keep record of the contents of the portal, our newly created web part’s information doesn’t exist in the database. We need to add the web part to the Web Part Gallery before we can use it.&lt;/p&gt;                  &lt;p&gt;To do so, the following steps should be followed.&lt;/p&gt;                  &lt;p&gt;1. Click on the &lt;b&gt;Site Actions &lt;/b&gt;button and then select Site Settings.&lt;/p&gt;                  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SuQ_tVSkfbI/AAAAAAAABHk/zYQN5u99knk/s1600-h/clip_image010%5B5%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image010" border="0" alt="clip_image010" src="http://lh3.ggpht.com/_iuwZHhydmEs/SuQ_uU_x6MI/AAAAAAAABHo/OD4wZwCJRWA/clip_image010_thumb%5B2%5D.jpg?imgmax=800" width="672" height="421" /&gt;&lt;/a&gt;&lt;/p&gt;                  &lt;p&gt;2. On the &lt;b&gt;site settings &lt;/b&gt;page under Galleries column click on the &lt;b&gt;Web Parts.&lt;/b&gt;&lt;/p&gt;                  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SuQ_vTpaZeI/AAAAAAAABHs/K1v7QX9Zndk/s1600-h/clip_image012%5B5%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image012" border="0" alt="clip_image012" src="http://lh3.ggpht.com/_iuwZHhydmEs/SuQ_w6f_3KI/AAAAAAAABHw/07JwCE0SYww/clip_image012_thumb%5B2%5D.jpg?imgmax=800" width="680" height="404" /&gt;&lt;/a&gt;&lt;/p&gt;                  &lt;p&gt;3. On the &lt;b&gt;Web Part Gallery &lt;/b&gt;Page click on the &lt;b&gt;New &lt;/b&gt;button, to add the new web part assembly to the gallery.&lt;/p&gt;                  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SuQ_xnYkkrI/AAAAAAAABH0/r4FiphHymIY/s1600-h/clip_image014%5B5%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image014" border="0" alt="clip_image014" src="http://lh3.ggpht.com/_iuwZHhydmEs/SuQ_yiacR_I/AAAAAAAABH4/-AAD3Q5005E/clip_image014_thumb%5B2%5D.jpg?imgmax=800" width="675" height="419" /&gt;&lt;/a&gt;&lt;/p&gt;                  &lt;p&gt;4. On the &lt;b&gt;New Web Parts&lt;/b&gt; page locate the &lt;b&gt;NewWebPart&lt;/b&gt; in the list, check the check box on the left and click on the &lt;b&gt;Populate Gallery&lt;/b&gt;button the top of the page. This will result in the Web Part entry creation in the Web Part Gallery list, and hence it can be used from now on from the gallery. It can be notices easily that the Web Parts developed form the new Frame work of 2.0 have an extension of &lt;b&gt;.webpart&lt;/b&gt;after their names. Whereas in earlier versions, it was a &lt;b&gt;.dwp&lt;/b&gt; file. Both the &lt;b&gt;.webpart &lt;/b&gt; and &lt;b&gt;.dwp &lt;/b&gt; files are the XML definition of the Web Part.&lt;/p&gt;                  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SuQ_zpI1SaI/AAAAAAAABH8/zJArK6xnwyk/s1600-h/clip_image016%5B5%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image016" border="0" alt="clip_image016" src="http://lh4.ggpht.com/_iuwZHhydmEs/SuQ_0jh58VI/AAAAAAAABIA/_jFZC-SrYms/clip_image016_thumb%5B2%5D.jpg?imgmax=800" width="661" height="385" /&gt;&lt;/a&gt;&lt;/p&gt;                  &lt;p&gt;5. Until this step the web part is ready to be used on the site by selecting it from Web Part Gallery. Click on the &lt;b&gt;Site Actions &lt;/b&gt;button on the page and then select &lt;b&gt;Edit Page&lt;/b&gt;, this will modify the appearance of the page to enable the edit view. In this view Web Part Zones are highlighted so that a user can add a web part to the zone, Click on the &lt;b&gt;Add a Web Part&lt;/b&gt; button in the left zone to add the Web Part.&lt;/p&gt;                  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SuQ_1VoMZYI/AAAAAAAABIE/aUf9_WQjWEA/s1600-h/clip_image018%5B5%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image018" border="0" alt="clip_image018" src="http://lh3.ggpht.com/_iuwZHhydmEs/SuQ_2UrRIlI/AAAAAAAABII/BeRtn3pEPg0/clip_image018_thumb%5B2%5D.jpg?imgmax=800" width="662" height="384" /&gt;&lt;/a&gt;&lt;/p&gt;                  &lt;p&gt;6. Select the NewWebPart from the web part list . it is found under the &lt;b&gt;Misc &lt;/b&gt;section and then click on�&lt;b&gt;Advanced Web Part gallery and options.&lt;/b&gt;&lt;/p&gt;                  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SuQ_3STjt-I/AAAAAAAABIM/O3qy0m73-Lc/s1600-h/clip_image020%5B5%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image020" border="0" alt="clip_image020" src="http://lh5.ggpht.com/_iuwZHhydmEs/SuQ_4EEcp5I/AAAAAAAABIQ/XCePPHBL7lM/clip_image020_thumb%5B2%5D.jpg?imgmax=800" width="651" height="422" /&gt;&lt;/a&gt;&lt;/p&gt;                  &lt;p&gt;7. In the�&lt;b&gt;Add Web Part &lt;/b&gt;Pane at right , select &lt;b&gt;Home&amp;#160; Gallery &lt;/b&gt;and then drag the NewWebPart from the pane into the Web Part Zone.&lt;/p&gt;                  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SuQ_5FPPwdI/AAAAAAAABIU/aoLIXkDFH6Q/s1600-h/clip_image021%5B5%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image021" border="0" alt="clip_image021" src="http://lh3.ggpht.com/_iuwZHhydmEs/SuQ_6AmOtBI/AAAAAAAABIY/VW6_qRlSn1A/clip_image021_thumb%5B2%5D.jpg?imgmax=800" width="609" height="446" /&gt;&lt;/a&gt;&lt;/p&gt;                  &lt;p&gt;8. Click on the &lt;b&gt;Exit Edit Mode&lt;/b&gt; link on the page and the site will return to the view mode.&lt;/p&gt;                  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SuQ_6-av_EI/AAAAAAAABIc/3tXziNY-Asg/s1600-h/clip_image022%5B6%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image022" border="0" alt="clip_image022" src="http://lh6.ggpht.com/_iuwZHhydmEs/SuQ_73FG6aI/AAAAAAAABIg/w9QCWQFd3qg/clip_image022_thumb%5B3%5D.jpg?imgmax=800" width="569" height="431" /&gt;&lt;/a&gt;&lt;/p&gt;               &lt;/td&gt;             &lt;/tr&gt;           &lt;/tbody&gt;&lt;/table&gt;       &lt;/td&gt;        &lt;td width="5"&gt;&amp;#160;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td width="5"&gt;&amp;#160;&lt;/td&gt;        &lt;td&gt;&amp;#160;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-4172302388728067648?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/4172302388728067648/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2009/10/developing-and-deploying-custom-web.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/4172302388728067648'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/4172302388728067648'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2009/10/developing-and-deploying-custom-web.html' title='Developing and Deploying Custom Web Parts for SharePoint Portal 2007'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_iuwZHhydmEs/SuQ_lNwN9DI/AAAAAAAABHA/-DcMbuQ95nI/s72-c/clip_image001_thumb%5B2%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-2999945869545659171</id><published>2009-10-24T02:38:00.001-07:00</published><updated>2009-10-24T02:38:41.389-07:00</updated><title type='text'>Map IP Address to a Geographical Location</title><content type='html'>&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;On the Internet there is the concept of web site analytics that helps track all the visitors' activities and usage patterns. One of the dimensions to track is the geographical information of the visitors, which can be obtained by using the IP address information that is collected when a user lands on a Website. In this article, I will describe a simple process that enables your reporting system to display the geographical information of the visitors.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Scope&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;This article does not describe the process needed to capture the IP information from the user. This process is an application level solution that can be implemented on the front end with software like ASP.Net, PHP etc. The scope of this article is limited to the usage of the IP address to discover the geographical data. This data is composed of the Country, Region, City, Postal code and Area code where applicable. Some countries may not have the concept of postal code.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;What is an IP Address?&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;When a user lands on a web page, the web application has the ability to collect information from this user. One of these data elements is the IP address. The IP address has a format of 192.15.10.125, and it is a logical address assigned to a device. This is what identifies your Internet address, and it is composed of segments that identify your geographical location.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;What Do I need to Map an IP Address to a Geo Location?&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;In order to map the IP address to a geographical representation, the system needs the geographical data mapping. This data is provided by several companies. In this case, we are using the GEOLiteCity data, which is free. To obtain this data, visit&lt;a href="http://www.maxmind.com/app/geolitecity"&gt;http://www.maxmind.com/app/geolitecity&lt;/a&gt; and download the ZIP file which contains two files, Blocks and Location CSV. The block file maps an IP number range to a location. The location file has the geographical information. Please note that there are frequent updates to these files, so make sure you read the description of their services.&lt;/p&gt;  &lt;p&gt;In order to import this data to your database, one first needs to create the table definitions. We need to create the Geo Location and Block tables. This are the table definitions: (you can also download the scripts)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SuLK_qPgI9I/AAAAAAAABGU/3VRa346pLOA/s1600-h/clip_image001%5B5%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image001" border="0" alt="clip_image001" src="http://lh6.ggpht.com/_iuwZHhydmEs/SuLLAh91ERI/AAAAAAAABGY/jghG6wTWabM/clip_image001_thumb%5B2%5D.gif?imgmax=800" width="454" height="264" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Import the data using your preferred method. The first line on the CSV file is a copyright statement. The second line has the column headers, so make sure to skip the first line during the import process. I have also included a visitor log table which can be used to track the user's data. This table is very simple, and it does not include all the possible data elements that can be collected.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Solution&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Once the data has been imported, you will notice that the IP address in the data does not look anything like 192.15.10.125. The information is actually stored as an IP number. This numeric value is what allows us to do a range comparison. An IP number range is mapped to a particular location. This is what allows us to do the association, but the first step is to figure out how to convert an IP address to an IP number. This is where a user defined function can help us. We first need to convert the IP address to an IP number by using the ConvertIP2Num function below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SuLLBV73T8I/AAAAAAAABGc/OQZX9J7BXg8/s1600-h/clip_image002%5B6%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://lh4.ggpht.com/_iuwZHhydmEs/SuLLCYa8x7I/AAAAAAAABGg/EOj2d80OqcQ/clip_image002_thumb%5B3%5D.gif?imgmax=800" width="588" height="526" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This function first splits the IP address into its four segments (delimited by a dot). This is where XML becomes really handy. We just create an XML string and use the parser to do the split for us by selecting the XML nodes. We use the Row_Number() function to create a factor which will help us arrive to the segment weight (i.e. segment: 192 has rownumber:1 and weigh: 4-1 = 3) . We now apply the conversion formula which consists of assigning a zero based weight to each segment (zero starting from the right segment) and multiplying this segment by (256 ^ n) OR POWER (256,n) where n = weight. The final step is to add all the segment results. For example, IP 192.15.10.125 is converted as follows:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SuLLDLIDRBI/AAAAAAAABGk/gIYGOWV5j3M/s1600-h/clip_image003%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image003" border="0" alt="clip_image003" src="http://lh4.ggpht.com/_iuwZHhydmEs/SuLLEOwpRxI/AAAAAAAABGo/ZdOgL3Irr9w/clip_image003_thumb%5B1%5D.jpg?imgmax=800" width="426" height="217" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The result is the number that can be used to query the geo tables. To do this, you can create a query similar to the one below which returns the geographical information.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SuLLFPCWLJI/AAAAAAAABGs/gN4SFcnrmno/s1600-h/clip_image004%5B6%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://lh3.ggpht.com/_iuwZHhydmEs/SuLLGXurwiI/AAAAAAAABGw/wKsKCSNHyWY/clip_image004_thumb%5B3%5D.jpg?imgmax=800" width="622" height="258" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;One item to notice here is that the conversion from IP address to number would not perform as well when you are trying to query thousand of rows and using the function to do the conversion at run time. A better approach would be to have an additional column on the table the holds the IP address information. This column can store the IP number as well. (See IPNum column on the Visitor_log Table) This way the import job can populate this field, so there is no performance hit during the query or creation of the report. In addition, by storing both fields (IP Address and Num), you will not have a need to reverse the IP Num to IP Address.&lt;/p&gt;  &lt;p&gt;If you do need to reverse an IP Num to IP Address (to validate the process, etc), you can use the ConvertNum2IP function below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SuLLG3GPm0I/AAAAAAAABG0/YoonHHGua78/s1600-h/clip_image005%5B7%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image005" border="0" alt="clip_image005" src="http://lh4.ggpht.com/_iuwZHhydmEs/SuLLH71ipUI/AAAAAAAABG4/AmCaNuF2_xU/clip_image005_thumb%5B4%5D.gif?imgmax=800" width="612" height="471" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This function just reverses the process by dividing the IP Num by Power(256,n) and subtracting the result from the IP Num. Each segment result is then appended into a string with the corresponding IP Address format.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Conclusion:&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;With this article, I was able to show a simple process to create your own GEO lookup database and provide a solution to map the IP address to its location information. There are still other items to consider like automating the import process to download the new files, convert the IP address to the IP Num value, integrate this information in a data warehouse, and create reports that will show your marketing team in what regions the customers are located.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-2999945869545659171?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/2999945869545659171/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2009/10/map-ip-address-to-geographical-location.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/2999945869545659171'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/2999945869545659171'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2009/10/map-ip-address-to-geographical-location.html' title='Map IP Address to a Geographical Location'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_iuwZHhydmEs/SuLLAh91ERI/AAAAAAAABGY/jghG6wTWabM/s72-c/clip_image001_thumb%5B2%5D.gif?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-1385793781084617630</id><published>2009-10-20T06:20:00.001-07:00</published><updated>2009-10-20T06:20:50.985-07:00</updated><title type='text'>Facebook forget password Error :)</title><content type='html'>&lt;p&gt;   &lt;br /&gt;Hi,     &lt;br /&gt;    &lt;br /&gt;Just i forget my facebook account password and want to reset it. So i go to facebook website and then forget password and then trying to enter the Security Check words like the below screen shot&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/St25GmmGQGI/AAAAAAAABF8/UoFbdC--3wk/s1600-h/16.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="1" border="0" alt="1" src="http://lh3.ggpht.com/_iuwZHhydmEs/St25H5p6P8I/AAAAAAAABGA/qyCfLo8PtAo/1_thumb4.png?imgmax=800" width="541" height="388" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Because I am a developer, I can guess the technical problem as the function which compare the user input&amp;#160; and security check words is wrong .&lt;/p&gt;  &lt;p&gt;After you click Reset password, FB will send you an email with code to change your password despite of &lt;strong&gt;wrong input words&lt;/strong&gt; as shown on the above image.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/St25I8TtFII/AAAAAAAABGE/0DA-KHPvB6M/s1600-h/26.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="2" border="0" alt="2" src="http://lh4.ggpht.com/_iuwZHhydmEs/St25KFeyDXI/AAAAAAAABGI/KxsAossuNdM/2_thumb4.png?imgmax=800" width="543" height="278" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;May be&lt;/strong&gt; The below is the technical problem expectation     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; The below function of validating word will ignore the last character.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/St25LHFV_2I/AAAAAAAABGM/sgpFOCDp3UI/s1600-h/35.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="3" border="0" alt="3" src="http://lh6.ggpht.com/_iuwZHhydmEs/St25Maq_x2I/AAAAAAAABGQ/jwUmTc-FM7w/3_thumb3.png?imgmax=800" width="536" height="221" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I like catching the problems from big companies’ products :)&lt;/p&gt;  &lt;p&gt;Hope it being nice post for you.!&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-1385793781084617630?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/1385793781084617630/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2009/10/facebook-forget-password-error.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/1385793781084617630'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/1385793781084617630'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2009/10/facebook-forget-password-error.html' title='Facebook forget password Error :)'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_iuwZHhydmEs/St25H5p6P8I/AAAAAAAABGA/qyCfLo8PtAo/s72-c/1_thumb4.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-1721766549071455002</id><published>2009-08-02T07:34:00.001-07:00</published><updated>2009-08-02T07:34:56.027-07:00</updated><title type='text'>Part IV: Step by step procedure of how to install an assembly</title><content type='html'>&lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;    &lt;br /&gt;Now, we will see how to install an assembly using the merge module witch is a tool provided by the MS Visual Studio 2005. The merge module tool is used to wrap components designed especially in order to be shared later. Components can be dll files or user controls objects that are consumed, in general, by the developer who wants to use or reuse already existing components, for example, he can develop an&lt;a href="http://www.c-sharpcorner.com/UploadFile/yougerthen/501152008131829PM/5.aspx"&gt;application&lt;/a&gt; against given dll files. So, using this method can provide him possibility to enjoy with those dll's or component's services.    &lt;br /&gt;Assuming that we want deploy an assembly witch called ClassLibrary1 with this feature:&lt;/p&gt;  &lt;p&gt;using System;&lt;/p&gt;  &lt;p&gt;using System.Collections.Generic;&lt;/p&gt;  &lt;p&gt;using System.Text;&lt;/p&gt;  &lt;p&gt;using System.Windows.Forms;&lt;/p&gt;  &lt;p&gt;namespace ClassLibrary1&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;public class Class1&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;public Class1()   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; MessageBox.Show(&amp;quot;You are using ClassLibrary1&amp;quot;);&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;}   &lt;br /&gt;}    &lt;br /&gt;After building it, we save the project and we add a new one by clicking File, New and Project&amp;#160; &lt;br /&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnWjvZRPNnI/AAAAAAAABEo/bq5l6cBE_-Q/s1600-h/clip_image001%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image001" border="0" alt="clip_image001" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnWjw-mgxOI/AAAAAAAABEs/A8Y9BB4cnIQ/clip_image001_thumb%5B1%5D.gif?imgmax=800" width="383" height="224" /&gt;&lt;/a&gt;    &lt;br /&gt;&lt;b&gt;Figure 1     &lt;br /&gt;&lt;/b&gt;    &lt;br /&gt;After the merge module project is opened, select Module Retarget able Folder just at right under the File system target machine node, then, right click and select add, then select project output as the figure shows bellow:    &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnWjyAGz02I/AAAAAAAABEw/-jlpWQRW9nk/s1600-h/clip_image002%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnWjzKXhGjI/AAAAAAAABE0/3DdiInnvGm8/clip_image002_thumb%5B1%5D.gif?imgmax=800" width="390" height="261" /&gt;&lt;/a&gt;    &lt;br /&gt;&lt;b&gt;Figure 2     &lt;br /&gt;&lt;/b&gt;    &lt;br /&gt;Select the primary output element list representing the assembly that we want to deploy. If you want to deploy other elements such as documentation files to get support to the developers or XML serialization assemblies, you can add them with the primary output.    &lt;br /&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnWjz9VDqOI/AAAAAAAABE4/2DGKjrcuJew/s1600-h/clip_image003%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image003" border="0" alt="clip_image003" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnWj03HEwSI/AAAAAAAABE8/TRFzAI8pvAg/clip_image003_thumb%5B1%5D.gif?imgmax=800" width="306" height="362" /&gt;&lt;/a&gt;    &lt;br /&gt;&lt;b&gt;Figure 3     &lt;br /&gt;&lt;/b&gt;    &lt;br /&gt;Now, expand the Merge module properties grid and set the author name, for example, &amp;quot;Me&amp;quot; as the figure shows bellow:    &lt;br /&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnWj1kfaoMI/AAAAAAAABFA/UdCMhqvs9fI/s1600-h/clip_image004%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnWj2sNtwUI/AAAAAAAABFE/GtzHWY3SPsI/clip_image004_thumb%5B1%5D.gif?imgmax=800" width="425" height="408" /&gt;&lt;/a&gt;    &lt;br /&gt;&lt;b&gt;Figure 4     &lt;br /&gt;&lt;/b&gt;There is a property witch I find very useful by the way, I mean, the &amp;quot;Search Path&amp;quot; property used to determine the path used to localize assemblies, files or even merge modules on the development computer.    &lt;br /&gt;Now, build the solution and browse to the application directory, the merge module project with name &amp;quot;MergeModule1&amp;quot; is there. Browse to the debug file an open it. A file with *.msm extension is created; this file represents the merge module project output. The mission is not completely accomplished because the merge module can not be installed directly. To install it, we must add an Installer project in order to consume the merge module; in fact, this one can't be installed by its self.    &lt;br /&gt;So, add a new setup project by selecting File then Add then New Project, and select Setup Project    &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnWj3oA98ZI/AAAAAAAABFI/oY1nrGM7lJQ/s1600-h/clip_image005%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image005" border="0" alt="clip_image005" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnWj4k8kd4I/AAAAAAAABFM/hLZ5WjebXnA/clip_image005_thumb%5B1%5D.gif?imgmax=800" width="422" height="215" /&gt;&lt;/a&gt;    &lt;br /&gt;&lt;b&gt;Figure 5     &lt;br /&gt;&lt;/b&gt;    &lt;br /&gt;Now, select Application Folder then Add then Project output menu item and click on it.    &lt;br /&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnWj5fbZkoI/AAAAAAAABFQ/vfbWkxf8X80/s1600-h/clip_image006%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnWj6bLlQzI/AAAAAAAABFU/Y2BWuF59zwY/clip_image006_thumb%5B1%5D.gif?imgmax=800" width="468" height="283" /&gt;&lt;/a&gt;    &lt;br /&gt;&lt;b&gt;Figure 6     &lt;br /&gt;&lt;/b&gt;    &lt;br /&gt;Select the Merge Module 1 project in the combo box list as shown bellow:    &lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnWj7Fux75I/AAAAAAAABFc/b9UDAvFPwKQ/s1600-h/clip_image007%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image007" border="0" alt="clip_image007" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnWj9pIIycI/AAAAAAAABFg/aqC3iVt7sPw/clip_image007_thumb%5B1%5D.gif?imgmax=800" width="295" height="349" /&gt;&lt;/a&gt;    &lt;br /&gt;&lt;b&gt;Figure 7     &lt;br /&gt;&lt;/b&gt;    &lt;br /&gt;Expand the setup properties grid and change the author property &amp;quot;.&amp;quot; By &amp;quot;Me&amp;quot; and the Manufacturer property value &amp;quot;.&amp;quot; By &amp;quot;Me&amp;quot; before build the project, otherwise, it can not be installed later. Build the setup project. After that, select it, right click and choose install in the context menu and click on it.    &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnWj-nwRoWI/AAAAAAAABFk/ses58G_6G3Y/s1600-h/clip_image008%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnWj_gs--0I/AAAAAAAABFo/h5Czl0_5TBg/clip_image008_thumb%5B1%5D.gif?imgmax=800" width="414" height="277" /&gt;&lt;/a&gt;    &lt;br /&gt;&lt;b&gt;Figure 8     &lt;br /&gt;&lt;/b&gt;The install process will be launched.    &lt;br /&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnWkAbyVeRI/AAAAAAAABFs/RzyBCjeWVCE/s1600-h/clip_image009%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image009" border="0" alt="clip_image009" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnWkBSgaZdI/AAAAAAAABFw/TLTqLq2TzrM/clip_image009_thumb%5B1%5D.gif?imgmax=800" width="467" height="301" /&gt;&lt;/a&gt;    &lt;br /&gt;&lt;b&gt;Figure 9     &lt;br /&gt;&lt;/b&gt;    &lt;br /&gt;After the project deployment, swap to the configuration panel and open add and remove program. You can find the setup 1 among the installed programs.    &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnWkCD5L6BI/AAAAAAAABF0/6ZbDSK-Yois/s1600-h/clip_image010%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image010" border="0" alt="clip_image010" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnWkDWKVLvI/AAAAAAAABF4/jNvUMmemdzo/clip_image010_thumb%5B1%5D.gif?imgmax=800" width="513" height="193" /&gt;&lt;/a&gt;    &lt;br /&gt;&lt;b&gt;Figure 10     &lt;br /&gt;&lt;/b&gt;The developer, or let us say the intermediate user, can browse to %root%\ProgramFiles\Me, there, he can find the new installed dll file.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-1721766549071455002?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/1721766549071455002/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2009/08/part-iv-step-by-step-procedure-of-how.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/1721766549071455002'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/1721766549071455002'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2009/08/part-iv-step-by-step-procedure-of-how.html' title='Part IV: Step by step procedure of how to install an assembly'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_iuwZHhydmEs/SnWjw-mgxOI/AAAAAAAABEs/A8Y9BB4cnIQ/s72-c/clip_image001_thumb%5B1%5D.gif?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-4975405021858408275</id><published>2009-08-02T07:31:00.001-07:00</published><updated>2009-08-02T07:31:16.380-07:00</updated><title type='text'>Part III: Step by step procedure of how to install an assembly</title><content type='html'>&lt;p&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;    &lt;br /&gt;We have seen in previous articles how to install an assembly using both, the .NET Framework management console and the Global assembly cache tool provided by the NET Framework. Now we will se how to install a strong named assembly with the simplest manner.    &lt;br /&gt;We have seen in a previous article&amp;#160; how one can install a given assembly using the .Net Framework management console the Mscorcfg.msc. Now, we proceed to achieve the same goal but using another tool witch is the Global assembly cache tool cagutil.exe provided by the .Net framework.    &lt;br /&gt;To do that, follow those steps:    &lt;br /&gt;First of all, let us develop a simple assembly. To do that, follow those steps&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Create a new class library project and name it myAssembly&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnWjCoxys2I/AAAAAAAABD4/OMLGDhPFFF4/s1600-h/clip_image001%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image001" border="0" alt="clip_image001" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnWjDlU8wQI/AAAAAAAABD8/3f3jLnEJmXg/clip_image001_thumb%5B1%5D.gif?imgmax=800" width="496" height="363" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;&lt;b&gt;Figure 1&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Add this code to the editor&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;using System;&lt;/p&gt;  &lt;p&gt;using System.Collections.Generic;&lt;/p&gt;  &lt;p&gt;using System.Text;&lt;/p&gt;  &lt;p&gt;using System.Windows.Forms;&lt;/p&gt;  &lt;p&gt;namespace myAssembly&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;public class Class1&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;public Class1()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;MessageBox.Show(&amp;quot;You are using myAssembly&amp;quot;);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}   &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Save the project.     &lt;br /&gt;The GAC accepts only assemblies with strong names; there fore it is imperatively recommended to sign the assembly before adding it into GAC, otherwise when adding a none strongly assembly, a message indicates that the new assembly can not be added to the GAC appears and finally the action is failed. So, to sign myAssembly, go to myAssembly properties as shown bellow.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnWjEtVUH-I/AAAAAAAABEA/j10ydkNKdtM/s1600-h/clip_image002%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnWjFxWI_GI/AAAAAAAABEE/EQEU5B4-jw0/clip_image002_thumb%5B1%5D.gif?imgmax=800" width="493" height="272" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;&lt;b&gt;Figure 2&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Select&amp;#160; the signing tab and then check sign the assembly checkbox&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnWjGhFSwoI/AAAAAAAABEI/Or-jL1KRwBM/s1600-h/clip_image003%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image003" border="0" alt="clip_image003" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnWjHgexMbI/AAAAAAAABEM/snPN5zqfjcI/clip_image003_thumb%5B1%5D.gif?imgmax=800" width="386" height="213" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;&lt;b&gt;Figure 3&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Select New in the combo box as shown above. This dialog box appears&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnWjIa46eAI/AAAAAAAABEQ/chXThZYF2qY/s1600-h/clip_image004%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnWjJaPTwVI/AAAAAAAABEU/M8F6CBIALyI/clip_image004_thumb%5B1%5D.gif?imgmax=800" width="381" height="249" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;&lt;b&gt;Figure 4&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Enter the key file name with twelve characters, then enter a password with more than six characters and confirm it, then click Ok.     &lt;br /&gt;A file looks like this &lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnWjJwqmvDI/AAAAAAAABEY/kzZbMTvpjVs/s1600-h/clip_image005%5B3%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image005" border="0" alt="clip_image005" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnWjKoH9A6I/AAAAAAAABEc/qLUas9_2nEU/clip_image005_thumb.gif?imgmax=800" width="37" height="36" /&gt;&lt;/a&gt; is added to the &lt;a href="http://www.c-sharpcorner.com/UploadFile/yougerthen/401152008130743PM/4.aspx"&gt;application&lt;/a&gt; directory with *.snk as an extension witch is a Strong Name Key abbreviation. This file contains a random pair keys and it is provided to sign the assembly. This file can be generated also using the Strong name tool sn.exe provided by .NET framework.&lt;/li&gt;    &lt;li&gt;Browse to &amp;quot;C:\Windows\assembly&amp;quot; directory witch looks like bellow:&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnWjLrAFGMI/AAAAAAAABEg/qbimvsv7XPk/s1600-h/clip_image006%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnWjMrJ3OxI/AAAAAAAABEk/V8LDstNnge4/clip_image006_thumb%5B1%5D.gif?imgmax=800" width="439" height="276" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;&lt;b&gt;Figure 5&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Drag the assembly and drop it in this directory, that's all.&lt;/li&gt; &lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-4975405021858408275?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/4975405021858408275/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2009/08/part-iii-step-by-step-procedure-of-how.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/4975405021858408275'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/4975405021858408275'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2009/08/part-iii-step-by-step-procedure-of-how.html' title='Part III: Step by step procedure of how to install an assembly'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_iuwZHhydmEs/SnWjDlU8wQI/AAAAAAAABD8/3f3jLnEJmXg/s72-c/clip_image001_thumb%5B1%5D.gif?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-8193987343542294183</id><published>2009-08-02T07:28:00.001-07:00</published><updated>2009-08-02T07:28:45.627-07:00</updated><title type='text'>Installing an Assembly: Part II Using the Global Cache</title><content type='html'>&lt;p&gt;&lt;strong&gt;Introduction     &lt;br /&gt;&lt;/strong&gt;    &lt;br /&gt;We have seen in a previous article&amp;#160; how one can install a given assembly using the .Net Framework management console the Mscorcfg.msc. Now, we proceed to achieve the same goal but using another tool witch is the Global assembly cache tool cagutil.exe provided by the .Net framework.    &lt;br /&gt;&lt;strong&gt;To do that, follow those steps:&lt;/strong&gt;    &lt;br /&gt;First of all, let us develop a simple assembly. To do that, follow those steps&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;1. Create a new class library project and name it myAssembly&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;&lt;img border="0" alt="@1.gif" src="http://www.c-sharpcorner.com/UploadFile/yougerthen/301152008125757PM/Images/@1.gif" width="392" height="283" /&gt;      &lt;br /&gt;Figure 1&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;Add this code to the editor&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;using System;&lt;/p&gt;  &lt;p&gt;using System.Collections.Generic;&lt;/p&gt;  &lt;p&gt;using System.Text;&lt;/p&gt;  &lt;p&gt;using System.Windows.Forms;&lt;/p&gt;  &lt;p&gt;namespace myAssembly&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;public class Class1&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;public Class1()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;MessageBox.Show(&amp;quot;You are using myAssembly!!!&amp;quot;);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}   &lt;br /&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;Save the project.       &lt;br /&gt;The GAC accepts only assemblies with strong names ; there fore it is imperatively recommended to sign the assembly before adding it into GAC, otherwise when adding a none strongly assembly, a message indicates that the new assembly can not be added to the GAC appears and finally the action is failed. So, to sign myAssembly, go to myAssembly properties as shown bellow.&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;&lt;img border="0" alt="@2.gif" src="http://www.c-sharpcorner.com/UploadFile/yougerthen/301152008125757PM/Images/@2.gif" width="495" height="265" /&gt;      &lt;br /&gt;Figure 2&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;Select the signing tab and then check sign the assembly checkbox&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;&lt;img border="0" alt="@3.gif" src="http://www.c-sharpcorner.com/UploadFile/yougerthen/301152008125757PM/Images/@3.gif" width="495" height="265" /&gt;      &lt;br /&gt;Figure 3&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;Select New in the combo box as shown above. This dialog box appears&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;&lt;img border="0" alt="@4.gif" src="http://www.c-sharpcorner.com/UploadFile/yougerthen/301152008125757PM/Images/@4.gif" width="324" height="207" /&gt;      &lt;br /&gt;Figure 4&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;Enter the key file name with twelve characters, then enter a password with more than six characters and confirm it, then click Ok.       &lt;br /&gt;A file looks like this &lt;img border="0" alt="small.gif" src="http://www.c-sharpcorner.com/UploadFile/yougerthen/301152008125757PM/Images/small.gif" width="33" height="32" /&gt; is added to the application directory with *.snk as an extension witch is a Strong Name Key abbreviation. This file contains a random pair keys and it is provided to sign the assembly. This file can be generated also using the Strong name tool sn.exe&amp;#160; provided by .NET framework.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;Build the solution, save the project and close it.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;Open the console, Start--&amp;gt; Accessories--&amp;gt; Console&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;Browse to your .Net framework directory using the change directory cd command.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;Tape cagutil -I&amp;#160; myAssembly and the press enter and the windows shell will tell you that the assembly is installed in the assembly cache.&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-8193987343542294183?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/8193987343542294183/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2009/08/installing-assembly-part-ii-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/8193987343542294183'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/8193987343542294183'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2009/08/installing-assembly-part-ii-using.html' title='Installing an Assembly: Part II Using the Global Cache'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-978708573748626609</id><published>2009-08-02T07:27:00.001-07:00</published><updated>2009-08-02T07:27:31.435-07:00</updated><title type='text'>Step by step procedure of how to install an assembly: Part I</title><content type='html'>&lt;p&gt;&lt;strong&gt;Introduction     &lt;br /&gt;&lt;/strong&gt;    &lt;br /&gt;It is an assembly container provided by the .NET Framework especially to store assemblies shared and used by different .Net applications installed on a given computer or on a given network. It is located in a subdirectory of the root &lt;a href="http://www.c-sharpcorner.com/#"&gt;system&lt;/a&gt; but it can not be directly accessed except that administrator permission is given before. The GAC is accessed via the .NET configuration management console witch is represented bellow:    &lt;br /&gt;&lt;img border="0" alt="1.gif" src="http://www.c-sharpcorner.com/UploadFile/yougerthen/201152008123837PM/Images/1.gif" width="420" height="171" /&gt;    &lt;br /&gt;&lt;strong&gt;Figure 1     &lt;br /&gt;&lt;/strong&gt;Assume that an assembly is simultaneously used and/or reused by more than one developer or shared by more than one application. So, it should be shared by them all. Therefore using GAC is a good alternative. It is possible to install the assembly in the GAC and give developers privileges access to the system root rather than to copy it into each development station. It is possible that the assembly cache contains more than one version of the same assembly but it is important to mention in this context that assemblies' names don't have an extension like *.dll or *.exe when are displayed within the GAC list. Only the assembly name appears without any extensions, because when the common language runtime CLR looks for a targeted assembly, it can precise the corresponding assembly according to the application needs.&amp;#160; &lt;br /&gt;When an application is developed against an assembly, it depends on it, therefore it needs to locate it and exploit its services when running. First of all the common language runtime CLR, witch is responsible for executing the application program, verifies if the assembly is already referenced and used, if this is not the case, it search it, at second plan, in the application bin directory, after that, it is checked in the global assembly cache GAC, in a final step, the CLR checks information about the targeted assembly in the configuration file, in this step the code base located in the configuration file gives information about the targeted assembly. When the assembly is not or can not be found, an error occurs. And a message like this can be found in the error list:    &lt;br /&gt;&lt;img border="0" alt="2.gif" src="http://www.c-sharpcorner.com/UploadFile/yougerthen/201152008123837PM/Images/2.gif" width="629" height="80" /&gt;    &lt;br /&gt;&lt;strong&gt;Figure 2     &lt;br /&gt;&lt;/strong&gt;    &lt;br /&gt;&lt;strong&gt;Where can one find the Global Assembly Cache:     &lt;br /&gt;&lt;/strong&gt;    &lt;br /&gt;To obtain the assemblies' list in Global assembly cache, follow this path:    &lt;br /&gt;Click Start --&amp;gt; Configuration Panel --&amp;gt; Administration tools --&amp;gt; .Net Framework Configuration&amp;#160; &lt;br /&gt;The .NET Framework 2.0 Configuration management console is opened as bellow:    &lt;br /&gt;&lt;img border="0" alt="3.gif" src="http://www.c-sharpcorner.com/UploadFile/yougerthen/201152008123837PM/Images/3.gif" width="716" height="486" /&gt;    &lt;br /&gt;&lt;strong&gt;Figure 3     &lt;br /&gt;&lt;/strong&gt;    &lt;br /&gt;Expand the My Computer node within the tree just at right and then select the assembly cache node then click view List of assemblies in the assembly cache hyper link.    &lt;br /&gt;&lt;img border="0" alt="4.gif" src="http://www.c-sharpcorner.com/UploadFile/yougerthen/201152008123837PM/Images/4.gif" width="668" height="282" /&gt;    &lt;br /&gt;&lt;strong&gt;Figure 4     &lt;br /&gt;&lt;/strong&gt;    &lt;br /&gt;The assembly list is displayed as bellow:    &lt;br /&gt;&lt;img border="0" alt="5.gif" src="http://www.c-sharpcorner.com/UploadFile/yougerthen/201152008123837PM/Images/5.gif" width="610" height="411" /&gt;    &lt;br /&gt;&lt;strong&gt;Figure 5     &lt;br /&gt;&lt;/strong&gt;    &lt;br /&gt;&lt;strong&gt;How can one install an assembly in the GAC:     &lt;br /&gt;&lt;/strong&gt;    &lt;br /&gt;First of all, let us develop a simple assembly. To do that, follow those steps&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;Create a new class library project and name it myAssembly for example.&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;&lt;img border="0" alt="6.gif" src="http://www.c-sharpcorner.com/UploadFile/yougerthen/201152008123837PM/Images/6.gif" width="433" height="298" /&gt;&lt;img border="0" alt="6.gif" src="http://www.c-sharpcorner.com/UploadFile/yougerthen/201152008123837PM/Images/6.gif" width="433" height="298" /&gt;      &lt;br /&gt;Figure 6&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;Add this code to the editor.&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;using System;&lt;/p&gt;  &lt;p&gt;using System.Collections.Generic;&lt;/p&gt;  &lt;p&gt;using System.Text;&lt;/p&gt;  &lt;p&gt;using System.Windows.Forms;&lt;/p&gt;  &lt;p&gt;namespace myAssembly&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;public class Class1&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;public Class1()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;MessageBox.Show(&amp;quot;You are using myAssembly&amp;quot;);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;Save the project.       &lt;br /&gt;The GAC accepts only assemblies with strong names ; there fore it is imperatively recommended to sign the assembly before adding it into GAC, otherwise when adding a none strongly assembly, a message indicates that the new assembly can not be added to the GAC appears and finally the action is failed. So, to sign myAssembly, go to myAssembly properties as shown bellow.&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;&lt;img border="0" alt="7.gif" src="http://www.c-sharpcorner.com/UploadFile/yougerthen/201152008123837PM/Images/7.gif" width="547" height="293" /&gt;      &lt;br /&gt;Figure 7&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;Select the signing tab and then check Sign the assembly checkbox.&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;&lt;img border="0" alt="8.gif" src="http://www.c-sharpcorner.com/UploadFile/yougerthen/201152008123837PM/Images/8.gif" width="585" height="344" /&gt;      &lt;br /&gt;Figure 8&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;Select New in the combo box as shown above. This dialog box appears&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;&lt;img border="0" alt="9.gif" src="http://www.c-sharpcorner.com/UploadFile/yougerthen/201152008123837PM/Images/9.gif" width="421" height="252" /&gt;      &lt;br /&gt;Figure 9&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;Enter the key file name with twelve characters, then enter a password with more than six characters and confirm it, then click Ok.       &lt;br /&gt;A file looks like this &lt;img border="0" alt="small.gif" src="http://www.c-sharpcorner.com/UploadFile/yougerthen/201152008123837PM/Images/small.gif" width="33" height="32" /&gt; is added to the application directory with *.snk as an extension witch is a Strong Name Key abbreviation. This file contains a random pair keys and it is provided to sign the assembly. This file can be generated also using the Strong name tool sn.exe provided by .NET framework.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;Build the solution, save the project and close it.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;Switch to the .Net Framework management console and right click on the Assembly cache node, a context menu appears.&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;Click add menu item, the open dialog box appears. &lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;&lt;img border="0" alt="10.gif" src="http://www.c-sharpcorner.com/UploadFile/yougerthen/201152008123837PM/Images/10.gif" width="526" height="162" /&gt;      &lt;br /&gt;Figure 10&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;     &lt;p&gt;Browse to the assembly location and then click open. The assembly will be added to the global assembly cache without any problems.&lt;/p&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-978708573748626609?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/978708573748626609/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2009/08/step-by-step-procedure-of-how-to.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/978708573748626609'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/978708573748626609'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2009/08/step-by-step-procedure-of-how-to.html' title='Step by step procedure of how to install an assembly: Part I'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-8231832511020214785</id><published>2009-08-02T00:32:00.001-07:00</published><updated>2009-08-02T00:32:12.572-07:00</updated><title type='text'>Google's Static Map API WebControl</title><content type='html'>&lt;p&gt;· &lt;a href="http://www.codeproject.com/KB/webforms/GoogleStaticMapWebControl/GStaticMap.zip"&gt;Download source - 5.56 KB&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;· &lt;a href="http://www.codeproject.com/KB/webforms/GoogleStaticMapWebControl/GStaticMapTest.zip"&gt;Download demo - 19.24 KB&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;GStaticMap is an ASP.NET WebControl allowing you to build and show a static map image with optionally some markers, a path, etc. using &lt;a href="http://code.google.com/apis/maps/documentation/staticmaps/"&gt;Google’s Static Maps API&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Here is a quick sample, showing you what you can quickly and easily produce with it:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnVAPF166OI/AAAAAAAABAU/9bVlYGIBgL8/s1600-h/clip_image001%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image001" border="0" alt="clip_image001" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnVAQdtjHZI/AAAAAAAABAY/sczXoFWnOaA/clip_image001_thumb%5B1%5D.gif?imgmax=800" width="392" height="251" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This sample can be achieved with some lines of code in the code-behind, or directly in your ASPX page:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnVAQwJzzVI/AAAAAAAABAc/mLtYdOmIvww/s1600-h/clip_image002%5B27%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnVASFRXt-I/AAAAAAAABAg/VZVXWPzA5DE/clip_image002_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GStaticMap ID=&amp;quot;gsmTestMap&amp;quot; AutomaticZoomLevel=&amp;quot;true&amp;quot;&lt;/p&gt;  &lt;p&gt;AutomaticCenter=&amp;quot;true&amp;quot; Width=&amp;quot;320&amp;quot; Height=&amp;quot;200&amp;quot; Type=&amp;quot;RoadMap&amp;quot;&lt;/p&gt;  &lt;p&gt;ZoomLevel=&amp;quot;12&amp;quot; Key=&amp;quot;put_yours_here&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;Center Latitude=&amp;quot;45.759723&amp;quot; Longitude=&amp;quot;4.842223&amp;quot;&amp;gt;&amp;lt;/Center&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;Markers&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GMarker Latitude=&amp;quot;45.859723&amp;quot; Longitude=&amp;quot;4.842223&amp;quot; Letter=&amp;quot;a&amp;quot;&lt;/p&gt;  &lt;p&gt;Color=&amp;quot;Red&amp;quot;&amp;gt;&amp;lt;/asp:GMarker&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GMarker Latitude=&amp;quot;45.759723&amp;quot; Longitude=&amp;quot;5.042223&amp;quot; Letter=&amp;quot;b&amp;quot;&lt;/p&gt;  &lt;p&gt;Color=&amp;quot;Green&amp;quot;&amp;gt;&amp;lt;/asp:GMarker&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GMarker Latitude=&amp;quot;45.659723&amp;quot; Longitude=&amp;quot;4.842223&amp;quot; Letter=&amp;quot;c&amp;quot;&lt;/p&gt;  &lt;p&gt;Color=&amp;quot;Blue&amp;quot;&amp;gt;&amp;lt;/asp:GMarker&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GMarker Latitude=&amp;quot;45.759723&amp;quot; Longitude=&amp;quot;4.642223&amp;quot; Color=&amp;quot;Green&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GMarker&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/Markers&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;Paths&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GPath Color=&amp;quot;blue&amp;quot; Opacity=&amp;quot;255&amp;quot; Weight=&amp;quot;5&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;Points&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GCoordinate Latitude=&amp;quot;45.859723&amp;quot; Longitude=&amp;quot;4.842223&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GCoordinate&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GCoordinate Latitude=&amp;quot;45.759723&amp;quot; Longitude=&amp;quot;5.042223&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GCoordinate&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GCoordinate Latitude=&amp;quot;45.659723&amp;quot; Longitude=&amp;quot;4.842223&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GCoordinate&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/Points&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GPath&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GPath Color=&amp;quot;red&amp;quot; Opacity=&amp;quot;128&amp;quot; Weight=&amp;quot;5&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;Points&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GCoordinate Latitude=&amp;quot;45.659723&amp;quot; Longitude=&amp;quot;4.842223&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GCoordinate&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GCoordinate Latitude=&amp;quot;45.759723&amp;quot; Longitude=&amp;quot;4.642223&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GCoordinate&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GCoordinate Latitude=&amp;quot;45.859723&amp;quot; Longitude=&amp;quot;4.842223&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GCoordinate&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/Points&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GPath&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/Paths&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GStaticMap&amp;gt;&lt;/p&gt;  &lt;p&gt;The generated URL is the following (I've added some spaces to wrap the URL and removed my API key):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnVATJ34ThI/AAAAAAAABAk/T2W5FZlOftM/s1600-h/clip_image002%5B1%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[1]" border="0" alt="clip_image002[1]" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnVAUJ0sH3I/AAAAAAAABAo/f9oDnrtgA94/clip_image002%5B1%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;http://maps.google.com/staticmap?size = 320x200 &amp;amp; maptype = roadmap &lt;/p&gt;  &lt;p&gt;&amp;amp; markers = 45.859723,4.842223,reda | 45.759723,5.042223,greenb | &lt;/p&gt;  &lt;p&gt;45.659723,4.842223,bluec | 45.759723,4.642223,green &amp;amp; path = rgba:0x0000ffff,weight:5 &lt;/p&gt;  &lt;p&gt;| 45.859723,4.842223 | 45.759723,5.042223 | 45.659723,4.842223 &amp;amp; &lt;/p&gt;  &lt;p&gt;path = rgba:0xff000080,weight:5 | 45.659723,4.842223 | 45.759723,4.642223 &lt;/p&gt;  &lt;p&gt;| 45.859723,4.842223 &amp;amp; key = put_yours_here.&lt;/p&gt;  &lt;p&gt;Note that this WebControl is a sequel of my previous &lt;a href="http://www.codeproject.com/KB/webforms/GoogleMapData.aspx"&gt;MapData&lt;/a&gt; WebControl, &lt;b&gt;replacing&lt;/b&gt; it.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Background&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;First, you'll need to sign up for a &lt;b&gt;free&lt;/b&gt; &lt;a href="http://code.google.com/apis/maps/signup.html"&gt;Google Maps API key&lt;/a&gt; if you don't have one. Connect with your Google account and put your domain name root (including the TCP/IP port).&lt;/p&gt;  &lt;p&gt;Please note that I didn't provide my API key in the sample project, you'll have to put yours if you want to run the tests (just replace all &amp;quot;put_yours_here&amp;quot; occurrences with your key)&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Classes Overview / Code Design&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Our goal is to display a map with, optionally, some markers and a path. Since the map will be rendered as an image (img tag), there is no need to reinvent the wheel: we'll derive our GStaticMap WebControl from System.Web.UI.Image.&lt;/p&gt;  &lt;p&gt;It’s now time to think about the classes that will be the foundations of our WebControl. First, we have a static map (GStaticMap class); this map will use:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;A center based on a coordinate (GCoordinate class)&lt;/li&gt;    &lt;li&gt;A collection of markers (GMarker class) themselves based on coordinates (GCoordinate class)&lt;/li&gt;    &lt;li&gt;A collection of paths (GPath class), themselves based on a collection of coordinates (GCoordinate class)&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Here is the class diagram (included in the sample project):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnVAVTURttI/AAAAAAAABAs/gxzicJs7kS8/s1600-h/clip_image004%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnVAWSBJFZI/AAAAAAAABAw/a_pU-7WkVl4/clip_image004_thumb%5B1%5D.jpg?imgmax=800" width="441" height="341" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The next step is to more deeply describe our classes. So:&lt;/p&gt;  &lt;p&gt;A &lt;b&gt;static map&lt;/b&gt; is defined by the following properties:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;A width (integer, inherited from Image)&lt;/li&gt;    &lt;li&gt;A height (integer, inherited from Image)&lt;/li&gt;    &lt;li&gt;A center (using our GCoordinate class, optional when there is at least one marker)&lt;/li&gt;    &lt;li&gt;A zoom level (integer, optional when there is at least one marker, from 1 to 19)&lt;/li&gt;    &lt;li&gt;A rendering type (enumerator, optional: roadmap by default, or designed for mobile devices)&lt;/li&gt;    &lt;li&gt;An image format (enumerator, optional: GIF, JPEG or PNG)&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;A &lt;b&gt;marker&lt;/b&gt; is defined by the following properties:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;A color (enumerator, optional: the Static Map API restricts them to red, by default, blue, or green)&lt;/li&gt;    &lt;li&gt;An optional letter (character, optional, from A to Z)&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;A &lt;b&gt;path&lt;/b&gt; is defined by the following properties:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;A color (you can define it either with a known color from RGB values)&lt;/li&gt;    &lt;li&gt;An optional opacity (integer, optional: from 0 to 255)&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;A &lt;b&gt;coordinate&lt;/b&gt; is defined by the following properties:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;A latitude (double)&lt;/li&gt;    &lt;li&gt;A longitude (double)&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;Making the Code – Coordinate Class (GCoordinate)&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;It’s now time for some code.&lt;/p&gt;  &lt;p&gt;We'll start our control with the coordinate class (GCoordinate). It’s a &amp;quot;small&amp;quot; class based on two doubles, constructors, and a query string serialization. Here is the class (tips and tricks are explained after):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnVAXaJkN_I/AAAAAAAABA4/L8RmM_yQgAw/s1600-h/clip_image002%5B2%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[2]" border="0" alt="clip_image002[2]" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnVAYegCc2I/AAAAAAAABA8/kmBheyzHaC4/clip_image002%5B2%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Represents a Google Coordinate&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[Serializable]&lt;/p&gt;  &lt;p&gt;[ToolboxData(&amp;quot;&amp;lt;{0}:GCoordinate Latitude='' &lt;/p&gt;  &lt;p&gt;Longitude='' runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/{0}:GCoordinate&amp;gt;&amp;quot;)]&lt;/p&gt;  &lt;p&gt;public class GCoordinate&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;#region Instance members&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Latitude&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;private double _latitude;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Longitude&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;private double _longitude;&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;#region Accessors&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Latitude&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[Bindable(true)]&lt;/p&gt;  &lt;p&gt;[Category(&amp;quot;Coordinate&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[DefaultValue(&amp;quot;&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[Localizable(false)]&lt;/p&gt;  &lt;p&gt;public double Latitude&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get { return _latitude; }&lt;/p&gt;  &lt;p&gt;set { _latitude = value; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Longitude&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[Bindable(true)]&lt;/p&gt;  &lt;p&gt;[Category(&amp;quot;Coordinate&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[DefaultValue(&amp;quot;&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[Localizable(false)]&lt;/p&gt;  &lt;p&gt;public double Longitude&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get { return _longitude; }&lt;/p&gt;  &lt;p&gt;set { _longitude = value; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;#region Constructors&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Constructor&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;param&lt;/i&gt;&lt;i&gt; &lt;/i&gt;&lt;i&gt;name=&amp;quot;latitude&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;param&lt;/i&gt;&lt;i&gt; &lt;/i&gt;&lt;i&gt;name=&amp;quot;longitude&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public GCoordinate()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Constructor&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public GCoordinate(double latitude, double longitude)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;SetCoordinate(latitude, longitude);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;#region Utilities&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Serialize data as a query string part&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Format : {latitude,longitude}&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;internal virtual string SerializeAsQueryString()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;return string.Format(&amp;quot;{0},{1}&amp;quot;, AngularValueToString(Latitude, 6), &lt;/p&gt;  &lt;p&gt;AngularValueToString(Longitude, 6));&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Format an angular value to be used by GStaticMap&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;param&lt;/i&gt;&lt;i&gt; &lt;/i&gt;&lt;i&gt;name=&amp;quot;angularValue&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;param&lt;/i&gt;&lt;i&gt; &lt;/i&gt;&lt;i&gt;name=&amp;quot;fixedLength&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;private string AngularValueToString(double angularValue, int precision)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;return angularValue.ToString(&amp;quot;F&amp;quot; + precision, &lt;/p&gt;  &lt;p&gt;CultureInfo.CreateSpecificCulture(&amp;quot;en-US&amp;quot;));&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;internal void SetCoordinate(double latitude, double longitude)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;_latitude = latitude;&lt;/p&gt;  &lt;p&gt;_longitude = longitude;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;First, I've added the [Serializable] attribute before the class declaration, this is needed in order to store the class in the ViewState (as a serializedstring).&lt;/p&gt;  &lt;p&gt;Secondly, let's have a look at the serialization methods: the AngularValueToString method converts a double value to a formatted string (localized to en-US culture for the decimal point), and SerializeAsQueryString is an internal (to be accessed by other classes of the same assembly) method making use of AngularValueToString to output the coordinate as query string parameters (braces are not relevant).&lt;/p&gt;  &lt;p&gt;Output: {latitude},{longitude}&lt;/p&gt;  &lt;p&gt;Finally, we have a SetCoordinate method that will allow us to modify the latitude and longitude in a single call.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Making the Code – Marker Class (GMarker)&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;A marker will be outputted like this on the map: &lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnVAY-x2IxI/AAAAAAAABBA/T3-ra72L6oI/s1600-h/clip_image006%5B3%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnVAZ_qb_-I/AAAAAAAABBE/mlSu04sz084/clip_image006_thumb.gif?imgmax=800" width="20" height="34" /&gt;&lt;/a&gt; (color and letter are customizable)&lt;/p&gt;  &lt;p&gt;First, we have an enumerator with available colors:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnVAanYsDeI/AAAAAAAABBI/xnEQbzmOniU/s1600-h/clip_image002%5B3%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[3]" border="0" alt="clip_image002[3]" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnVAbsPp3eI/AAAAAAAABBM/KD_jFk7z37c/clip_image002%5B3%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;#region Enumerators&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Available Google Static Marker colors&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public enum GMarkerColor&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;Red,&lt;/p&gt;  &lt;p&gt;Blue,&lt;/p&gt;  &lt;p&gt;Green&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;Then, the marker class (GMarker) inherits from GCoordinate and extends it with marker’s color and letter (tips and tricks are explained after):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnVAcB7NI6I/AAAAAAAABBQ/pLyfGrF0mZU/s1600-h/clip_image002%5B4%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[4]" border="0" alt="clip_image002[4]" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnVAdASp-6I/AAAAAAAABBU/0-JyIOmELhc/clip_image002%5B4%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Represent a Google Marker&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; {latitude} (required) specifies a latitudinal value with precision to &lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; 6 decimal places.&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; {longitude} (required) specifies a longitudinal value with precision to &lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; 6 decimal places.&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; {color} (optional) specifies a color from the set {red,blue,green}.&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; {alpha-character} (optional) specifies a single lowercase alphabetic character &lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; from the set {a-z}.&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[Serializable]&lt;/p&gt;  &lt;p&gt;[ToolboxData(&amp;quot;&amp;lt;{0}:GMarker Latitude='' Longitude='' &lt;/p&gt;  &lt;p&gt;Letter='a' Color='Red' runat=&amp;quot;server&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/{0}:GMarker&amp;gt;&amp;quot;)]&lt;/p&gt;  &lt;p&gt;public class GMarker : GCoordinate&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;#region Instance members&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Marker color&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;private MarkerColor _color;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Marker letter (optional)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;private char? _letter;&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;#region Accessors&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Marker color&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[Bindable(true)]&lt;/p&gt;  &lt;p&gt;[Category(&amp;quot;Appearance&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[DefaultValue(&amp;quot;Red&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[Localizable(false)]&lt;/p&gt;  &lt;p&gt;public MarkerColor Color&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get { return _color; }&lt;/p&gt;  &lt;p&gt;set { _color = value; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Marker letter (optional)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[Bindable(true)]&lt;/p&gt;  &lt;p&gt;[Category(&amp;quot;Appearance&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[DefaultValue(&amp;quot;a&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[Localizable(false)]&lt;/p&gt;  &lt;p&gt;public char? Letter&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get { return _letter; }&lt;/p&gt;  &lt;p&gt;set { _letter = value; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;#region Constructors&lt;/p&gt;  &lt;p&gt;public GMarker()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;public GMarker(double latitude, double longitude, MarkerColor color)&lt;/p&gt;  &lt;p&gt;: base(latitude, longitude)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;_color = color;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;public GMarker(double latitude, double longitude, MarkerColor color, char letter)&lt;/p&gt;  &lt;p&gt;: this(latitude, longitude, color)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;_letter = letter;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;#region Utilities&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Serialize data as a query string part&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Format : {latitude},{longitude},{color}{alpha-character}&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;internal override string SerializeAsQueryString()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;return string.Format&lt;/p&gt;  &lt;p&gt;(&lt;/p&gt;  &lt;p&gt;&amp;quot;{0},{1}{2}&amp;quot;,&lt;/p&gt;  &lt;p&gt;base.SerializeAsQueryString(),&lt;/p&gt;  &lt;p&gt;Enum.GetName(typeof(MarkerColor), Color).ToLower(),&lt;/p&gt;  &lt;p&gt;(Letter == null ? &amp;quot;&amp;quot; : Letter.ToString())&lt;/p&gt;  &lt;p&gt;);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;Once again, I added the [Serializable] attribute (always for the ViewState).&lt;/p&gt;  &lt;p&gt;The most interesting code is the serialization part: SerializeAsQueryString is again with internal visibility (to be accessed by other classes of the same assembly) and outputs the marker as query string parameters with the help of its base class (for the coordinate part). It also shows how to retrieve the name of an enumerator value (yes, it’s verbose…) transformed to lower characters in order to respect the Google Static Map API (braces are not relevant).&lt;/p&gt;  &lt;p&gt;Serialization output: {coordinate},{color}{letter}&lt;/p&gt;  &lt;p&gt;Note that the letter is optional, so we only output it if it’s not null (thanks to the ternary operator, gracefully used here).&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Making the Code – Path Class (GPath)&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The last step before building the static map class is the path class (GPath).&lt;/p&gt;  &lt;p&gt;First, we have an enumerator with available color types (simple RBG, or RGB with Alpha channel):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnVAdhhpRHI/AAAAAAAABBY/xV3gKcw2e5w/s1600-h/clip_image002%5B5%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[5]" border="0" alt="clip_image002[5]" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnVAevSv9QI/AAAAAAAABBc/J5epUU9TkF0/clip_image002%5B5%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;#region Enumerators&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Available Google Static Marker colors&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public enum GPathColorType&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;RGB,&lt;/p&gt;  &lt;p&gt;RGBA&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;This class doesn't inherit from any class but makes use of the coordinate one (GCoordinate) to store the points (tips and tricks are explained after):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnVAfAzNypI/AAAAAAAABBg/40bIgE4fYF8/s1600-h/clip_image002%5B6%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[6]" border="0" alt="clip_image002[6]" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnVAf3bs_aI/AAAAAAAABBk/WgakjmaNzTk/clip_image002%5B6%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Represent a Google Path&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[Serializable]&lt;/p&gt;  &lt;p&gt;[ToolboxData(&amp;quot;&amp;lt;{0}:GPath runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/{0}:GPath&amp;gt;&amp;quot;)]&lt;/p&gt;  &lt;p&gt;public class GPath&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;#region Enumerators&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Available Google Static Marker colors&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;protected enum PathColorType&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;RGB,&lt;/p&gt;  &lt;p&gt;RGBA&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;#region Instance members&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Path color (default blue)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;private System.Drawing.Color _color = System.Drawing.Color.Blue;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Path thickness, in pixels&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;private int _weight = 1;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Path opacity from 0% to 100% (optional)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;private int? _opacity;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; List of points&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;private List&amp;lt;GCoordinate&amp;gt; _points = new List&amp;lt;GCoordinate&amp;gt;();&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;#region Accessors&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Path color&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[Bindable(true)]&lt;/p&gt;  &lt;p&gt;[Category(&amp;quot;Appearance&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[DefaultValue(&amp;quot;Red&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[Localizable(false)]&lt;/p&gt;  &lt;p&gt;public System.Drawing.Color Color&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get { return _color; }&lt;/p&gt;  &lt;p&gt;set { _color = value; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Path thickness, in pixels&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[Bindable(true)]&lt;/p&gt;  &lt;p&gt;[Category(&amp;quot;Appearance&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[DefaultValue(&amp;quot;1&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[Localizable(false)]&lt;/p&gt;  &lt;p&gt;public int Weight&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get { return _weight; }&lt;/p&gt;  &lt;p&gt;set { _weight = value; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Path opacity from 0 to 255 (optional)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[Bindable(true)]&lt;/p&gt;  &lt;p&gt;[Category(&amp;quot;Appearance&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[DefaultValue(&amp;quot;1&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[Localizable(false)]&lt;/p&gt;  &lt;p&gt;public int? Opacity&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get { return _opacity; }&lt;/p&gt;  &lt;p&gt;set { _opacity = value; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Paths (optional)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[&lt;/p&gt;  &lt;p&gt;DesignerSerializationVisibility(DesignerSerializationVisibility.Content),&lt;/p&gt;  &lt;p&gt;PersistenceMode(PersistenceMode.InnerDefaultProperty),&lt;/p&gt;  &lt;p&gt;Editor(typeof(List&amp;lt;GCoordinate&amp;gt;), typeof(System.Drawing.Design.UITypeEditor)),&lt;/p&gt;  &lt;p&gt;]&lt;/p&gt;  &lt;p&gt;public List&amp;lt;GCoordinate&amp;gt; Points&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get { return _points; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;#region Constructors&lt;/p&gt;  &lt;p&gt;public GPath()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;public GPath(System.Drawing.Color color, int weight)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;Color = color;&lt;/p&gt;  &lt;p&gt;Weight = weight;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;public GPath(System.Drawing.Color color, int weight, int opacity)&lt;/p&gt;  &lt;p&gt;: this(color, weight)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;Opacity = opacity;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;#region Utilities&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Serialize data as a query string part&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Format : path=pathColorType:pathColorValue,weight:pathWeight&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; |pathPoint1|pathPoint2|pathPoint3|...&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;internal string SerializeAsQueryString()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Checks&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Get color type&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;PathColorType pathColorType = (Opacity == null) ? PathColorType.RGB : &lt;/p&gt;  &lt;p&gt;PathColorType.RGBA;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Get color value&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;string colorValue = string.Format(&amp;quot;{0:x8}&amp;quot;, Color.ToArgb()).Substring(2, 6);&lt;/p&gt;  &lt;p&gt;if (Opacity != null)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;colorValue += string.Format(&amp;quot;{0:x2}&amp;quot;, Opacity);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Serialize path's header&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;string serializedPath = string.Format&lt;/p&gt;  &lt;p&gt;(&lt;/p&gt;  &lt;p&gt;&amp;quot;path={0}:0x{1},weight:{2}|&amp;quot;,&lt;/p&gt;  &lt;p&gt;(pathColorType == PathColorType.RGB) ? &amp;quot;rgb&amp;quot; : &amp;quot;rgba&amp;quot;,&lt;/p&gt;  &lt;p&gt;colorValue,&lt;/p&gt;  &lt;p&gt;_weight&lt;/p&gt;  &lt;p&gt;);&lt;/p&gt;  &lt;p&gt;&lt;i&gt;//Serialize path's points&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;List&amp;lt;string&amp;gt; serializedPoints = new List&amp;lt;string&amp;gt;();&lt;/p&gt;  &lt;p&gt;foreach(GCoordinate coordinate in Points)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;serializedPoints.Add(coordinate.SerializeAsQueryString());&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Returns serialized path&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;return serializedPath + string.Join(&amp;quot;|&amp;quot;, serializedPoints.ToArray());&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;As usual, this class is serializable ([Serializable] attribute) in order to be stored in the ViewState.&lt;/p&gt;  &lt;p&gt;The serialization part (SerializeAsQueryString method) is again with internal visibility (to be accessed by other classes of the same assembly) and outputs the path as query string parameters with the help of the coordinate class (braces and brackets are not relevant).&lt;/p&gt;  &lt;p&gt;Serialization output: path={rgb|rgba}:0x{ color}[{alpha}],weight:{weight}|{&lt;i&gt; coordinate&lt;/i&gt;}|{&lt;i&gt;coordinate&lt;/i&gt;}...&lt;/p&gt;  &lt;p&gt;Note that the opacity is optional and the color type will be output as &amp;quot;rgb&amp;quot; or &amp;quot;rgba&amp;quot; according to its value (note the use of the ternary operator).&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Making the Code – Static Map Class (GStaticMap)&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Here is the final part of our WebControl: the WebControl itself. I've sliced out the interesting parts in order to comment them step by step (you may open the whole code in your Visual Studio).&lt;/p&gt;  &lt;p&gt;First, we have useful enumerators for the map type, the map’s image format and for the zoom levels bounds:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnVAg3sPP0I/AAAAAAAABBo/BvWCRXTzDn8/s1600-h/clip_image002%5B7%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[7]" border="0" alt="clip_image002[7]" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnVAhu5djaI/AAAAAAAABBs/rHNlq8Yo_zQ/clip_image002%5B7%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;#region Enumerators&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Available map types&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public enum GStaticMapType&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;Mobile,&lt;/p&gt;  &lt;p&gt;RoadMap&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Available image formats&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public enum GStaticMapImageFormat&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;GIF,&lt;/p&gt;  &lt;p&gt;JPG,&lt;/p&gt;  &lt;p&gt;PNG32&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Available zoom levels&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public enum GStaticMapZoomLevel : uint&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;Mini = 1,&lt;/p&gt;  &lt;p&gt;Maxi = 19&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;Here is the declaration of the static map class (GStaticMap), inheriting from System.Web.UI.WebControls.Image:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnVAiYoV8vI/AAAAAAAABBw/4A0Oz-Wh2oE/s1600-h/clip_image002%5B8%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[8]" border="0" alt="clip_image002[8]" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnVAjUiCg3I/AAAAAAAABB0/MmoNj1JURrI/clip_image002%5B8%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;[ToolboxData(&amp;quot;&amp;lt;{0}:GStaticMap runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/{0}:GStaticMap&amp;gt;&amp;quot;)]&lt;/p&gt;  &lt;p&gt;public class GStaticMap : System.Web.UI.WebControls.Image&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;..........&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;We declare private instance members of our class.&lt;/p&gt;  &lt;p&gt;You'll notice that we have members relating to the automatic centering and automatic zooming features, which we will talk about in few minutes.&lt;/p&gt;  &lt;p&gt;I also make use of generics for the markers and paths lists. The last member is the Google API Key, don't forget to get yours!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnVAkLS-VeI/AAAAAAAABB4/DesdrTd-0sE/s1600-h/clip_image002%5B9%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[9]" border="0" alt="clip_image002[9]" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnVAlP3a9VI/AAAAAAAABB8/oC8MuyGUzuQ/clip_image002%5B9%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;#region Instance members&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Indicates if automatic center is enabled &lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; (available if at least one marker present)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;private bool _automaticCenter;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Indicates if automatic zoom level is enabled &lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; (available if at least one marker present)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;private bool _automaticZoomLevel;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt;Center (required if markers or paths not present)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;private GCoordinate _center;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; ZoomLevel (required if markers or paths not present)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;private uint? _zoomLevel = null;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Image format (optional)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;private MapImageFormat? _imageFormat = null;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Map type (optional)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;private MapType? _type = null;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; List of markers&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;private List&amp;lt;GMarker&amp;gt; _markers = new List&amp;lt;GMarker&amp;gt;();&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; List of paths&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;private List&amp;lt;GPath&amp;gt; _paths = new List&amp;lt;GPath&amp;gt;();&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Google Base API Key (required)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Go to http://code.google.com/apis/base/signup.html to get yours &lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; (it's free and doesn't require any subscription)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;private string _key;&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;It’s now time to declare our public accessors.&lt;/p&gt;  &lt;p&gt;Since we are making a WebControl, you'll notice that most of them have a Bindable attribute in order to become ASP.NET attributes (i.e. you can define them directly in the tag that you may declare in the ASPX page) and to be available in the design mode.&lt;/p&gt;  &lt;p&gt;Don't worry if you don't see the Center, Markers and Paths here, a specific region will covers them since they are now accessible as children in the ASPX page.&lt;/p&gt;  &lt;p&gt;Accessors are very interesting because they encapsulate the way they manage the value you pass or retrieve to them: have a look at the zoom level (ZoomLevel), and the setter (which becomes a method during the compilation) checks bounds with the help of the enumerator. By contrast, automatic center and automatic zoom accessors alter the return value through the getter (also transformed to a method by the compiler).&lt;/p&gt;  &lt;p&gt;The last interesting thing in this part is about the ImageUrl accessor. I make use of the new keyword as a modifier in order to redefine the base class’ImageUrl accessor. Here, I wanted ImageUrl to be readable but not settable (because it’s built by our class before rendering), so I only defined a getter returning the value of the base class accessor (base keyword):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnVAlw4WQOI/AAAAAAAABCA/oj30NqIcagQ/s1600-h/clip_image002%5B10%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[10]" border="0" alt="clip_image002[10]" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnVAmo9mOuI/AAAAAAAABCE/BjPbR7PWAj0/clip_image002%5B10%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;#region Accessors&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; ZoomLevel (required if markers or paths not present)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[Bindable(true)]&lt;/p&gt;  &lt;p&gt;[Category(&amp;quot;Appearance&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[DefaultValue(&amp;quot;MapZoomLevel.Mini&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[Localizable(false)]&lt;/p&gt;  &lt;p&gt;public uint? ZoomLevel&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get { return _zoomLevel; }&lt;/p&gt;  &lt;p&gt;set&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Check zoom bounds&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;if (value &amp;lt; (uint)MapZoomLevel.Mini) { value = (uint)MapZoomLevel.Mini; }&lt;/p&gt;  &lt;p&gt;else if (value &amp;gt; (uint)MapZoomLevel.Maxi) { value = (uint)MapZoomLevel.Maxi; }&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Apply new zoom&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;_zoomLevel = value;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Image format (optional)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[Bindable(true)]&lt;/p&gt;  &lt;p&gt;[Category(&amp;quot;Appearance&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[DefaultValue(&amp;quot;PNG&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[Localizable(false)]&lt;/p&gt;  &lt;p&gt;public MapImageFormat? ImageFormat&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get { return _imageFormat; }&lt;/p&gt;  &lt;p&gt;set { _imageFormat = value; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Map type (optional)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[Bindable(true)]&lt;/p&gt;  &lt;p&gt;[Category(&amp;quot;Appearance&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[DefaultValue(&amp;quot;RoadMap&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[Localizable(false)]&lt;/p&gt;  &lt;p&gt;public MapType? Type&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get { return _type; }&lt;/p&gt;  &lt;p&gt;set { _type = value; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Google Base API Key (required)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Go to http://code.google.com/apis/base/signup.html to get yours &lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; (it's free and doesn't require any subscription)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[Bindable(true)]&lt;/p&gt;  &lt;p&gt;[Category(&amp;quot;Google&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[DefaultValue(&amp;quot;&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[Localizable(false)]&lt;/p&gt;  &lt;p&gt;public string Key&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get { return _key; }&lt;/p&gt;  &lt;p&gt;set { _key = value; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Indicates if automatic center is enabled (available if at least one marker present)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[Bindable(true)]&lt;/p&gt;  &lt;p&gt;[Category(&amp;quot;Appearance&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[DefaultValue(&amp;quot;&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[Localizable(false)]&lt;/p&gt;  &lt;p&gt;public bool AutomaticCenter&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get { return _automaticCenter &amp;amp;&amp;amp; IsAutomaticAvailable; }&lt;/p&gt;  &lt;p&gt;set { _automaticCenter = value; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Indicates if automatic zoom level is enabled &lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; (available if at least one marker present)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[Bindable(true)]&lt;/p&gt;  &lt;p&gt;[Category(&amp;quot;Appearance&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[DefaultValue(&amp;quot;&amp;quot;)]&lt;/p&gt;  &lt;p&gt;[Localizable(false)]&lt;/p&gt;  &lt;p&gt;public bool AutomaticZoomLevel&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get { return _automaticZoomLevel &amp;amp;&amp;amp; IsAutomaticAvailable; }&lt;/p&gt;  &lt;p&gt;set { _automaticZoomLevel = value; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Redefine picture's ImageUrl to avoid any modification &lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; (since ImageUrl is built by the webcontrol)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public new string ImageUrl&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get { return base.ImageUrl; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Indicates whether automatic center and levels are available&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public bool IsAutomaticAvailable&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get { return (Markers.Count &amp;gt; 0 || Paths.Count &amp;gt; 0); }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;Here are the accessors that you can use directly in the ASPX page, the DesignerSerializationVisibility attribute for each of them make (according to MSDN) the code generator produce code for the contents of the object, rather than for the object itself (so you can access them in the ASPX page):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnVAnhZFo_I/AAAAAAAABCI/x5BBfWtscHI/s1600-h/clip_image002%5B11%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[11]" border="0" alt="clip_image002[11]" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnVAo_loVPI/AAAAAAAABCM/9es_7luVg5w/clip_image002%5B11%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;#region Childs&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Center (required if markers or paths not present)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]&lt;/p&gt;  &lt;p&gt;public GCoordinate Center&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;if (_center == null)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;_center = new GCoordinate();&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;return _center;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Markers (optional)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]&lt;/p&gt;  &lt;p&gt;public List&amp;lt;GMarker&amp;gt; Markers&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get { return _markers; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Paths (optional)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]&lt;/p&gt;  &lt;p&gt;public List&amp;lt;GPath&amp;gt; Paths&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get { return _paths; }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;Now, since we have all the needed members and attributes to complete our aim, it’s time to write the BuildUrl method that will produce the final URL, according to the Google Static Map API.&lt;/p&gt;  &lt;p&gt;Serialization output: http://maps.google.com/staticmap?&lt;i&gt;parameters.&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnVAqC7O2CI/AAAAAAAABCQ/3kN1_L5hFP8/s1600-h/clip_image002%5B12%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[12]" border="0" alt="clip_image002[12]" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnVArAMGK-I/AAAAAAAABCU/4J29E4t7ZXA/clip_image002%5B12%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;#region Utilities&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Build up the URL used to request the generated picture&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Format : http://maps.google.com/staticmap?parameters&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;private string BuildUrl()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Base URL (change if needed)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;string url = &amp;quot;http://maps.google.com/staticmap?&amp;quot;;&lt;/p&gt;  &lt;p&gt;List&amp;lt;string&amp;gt; parameters = new List&amp;lt;string&amp;gt;();&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Center (required if markers or paths not present)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;if (!AutomaticCenter)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;parameters.Add(&amp;quot;center=&amp;quot; + Center.SerializeAsQueryString());&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// ZoomLevel (required if markers or paths not present)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;if (!AutomaticZoomLevel)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;parameters.Add(&amp;quot;zoom=&amp;quot; + ZoomLevel);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Image size&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;parameters.Add(string.Format(&amp;quot;size={0}x{1}&amp;quot;, &lt;/p&gt;  &lt;p&gt;(int)Width.Value, (int)Height.Value));&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Image format (optional)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;if (ImageFormat != null)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;parameters.Add(&amp;quot;format=&amp;quot; + Enum.GetName(typeof(MapImageFormat), &lt;/p&gt;  &lt;p&gt;ImageFormat).ToLower());&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Map type (optional)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;if (Type != null)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;parameters.Add(&amp;quot;maptype=&amp;quot; + Enum.GetName(typeof(MapType), Type).ToLower());&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Markers (optional)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;if (Markers.Count &amp;gt; 0)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Gather markers in a string list&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;List&amp;lt;string&amp;gt; markers = new List&amp;lt;string&amp;gt;();&lt;/p&gt;  &lt;p&gt;foreach (GMarker poi in Markers)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;markers.Add(poi.SerializeAsQueryString());&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Add them as a parameter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;parameters.Add(string.Format&lt;/p&gt;  &lt;p&gt;(&amp;quot;markers={0}&amp;quot;, string.Join(&amp;quot;|&amp;quot;, markers.ToArray())));&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Paths (optional)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;if (Paths.Count &amp;gt; 0)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;foreach (GPath path in Paths)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Add them as a parameter&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;parameters.Add(path.SerializeAsQueryString());&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// ZoomLevel (required if markers or paths not present)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;if (Key != string.Empty)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;parameters.Add(&amp;quot;key=&amp;quot; + Key);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Build up and returns final URL&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;return url + string.Join(&amp;quot;&amp;amp;&amp;quot;, parameters.ToArray());&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;The next logical step is to set the ImageUrl accessor. The best moment to do this is just before the rendering, so we just have to overload the OnPreRendervirtual method to achieve this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnVArleQy8I/AAAAAAAABCY/iPo2pwBHREs/s1600-h/clip_image002%5B13%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[13]" border="0" alt="clip_image002[13]" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnVAsf6TBsI/AAAAAAAABCc/hqKYT5nCvAU/clip_image002%5B13%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;#region Methods&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Build the image url according to parameters and added points&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;param&lt;/i&gt;&lt;i&gt; &lt;/i&gt;&lt;i&gt;name=&amp;quot;e&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;protected override void OnPreRender(EventArgs e)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;base.OnPreRender(e);&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Set Image Url before rendering&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;base.ImageUrl = BuildUrl();&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;#endregion&lt;/p&gt;  &lt;p&gt;OK, our work is looking good now, but we have missed something… How will the state of our control be maintained after a postback? Obviously with theViewState, so here is the way to do this: we must overload the LoadViewState and SaveViewState virtual methods to, respectively load ViewStatevalues in the control and save the control values in the ViewState (you can also directly save or load some values on demand, by using accessors):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnVAtAv3I3I/AAAAAAAABCg/EaEvAkJackI/s1600-h/clip_image002%5B14%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[14]" border="0" alt="clip_image002[14]" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnVAuFSxl2I/AAAAAAAABCk/hWmJYDI4fIY/clip_image002%5B14%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Load viewstate values&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;param&lt;/i&gt;&lt;i&gt; &lt;/i&gt;&lt;i&gt;name=&amp;quot;savedState&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;protected override void LoadViewState(object savedState)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;base.LoadViewState(savedState);&lt;/p&gt;  &lt;p&gt;_center = (GCoordinate)ViewState[&amp;quot;Center&amp;quot;];&lt;/p&gt;  &lt;p&gt;ZoomLevel = (uint)ViewState[&amp;quot;ZoomLevel&amp;quot;];&lt;/p&gt;  &lt;p&gt;Type = (MapType)ViewState[&amp;quot;MapType&amp;quot;];&lt;/p&gt;  &lt;p&gt;Markers.AddRange(new List&amp;lt;GMarker&amp;gt;((GMarker[])ViewState[&amp;quot;Markers&amp;quot;]));&lt;/p&gt;  &lt;p&gt;Paths.AddRange(new List&amp;lt;GPath&amp;gt;((GPath[])ViewState[&amp;quot;Paths&amp;quot;]));&lt;/p&gt;  &lt;p&gt;Key = (string)ViewState[&amp;quot;Key&amp;quot;];&lt;/p&gt;  &lt;p&gt;AutomaticCenter = (bool)ViewState[&amp;quot;AutomaticCenter&amp;quot;];&lt;/p&gt;  &lt;p&gt;AutomaticZoomLevel = (bool)ViewState[&amp;quot;AutomaticZoomLevel&amp;quot;];&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Save viewstate values&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;protected override object SaveViewState()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;ViewState[&amp;quot;Center&amp;quot;] = _center;&lt;/p&gt;  &lt;p&gt;ViewState[&amp;quot;ZoomLevel&amp;quot;] = ZoomLevel;&lt;/p&gt;  &lt;p&gt;ViewState[&amp;quot;MapType&amp;quot;] = Type;&lt;/p&gt;  &lt;p&gt;ViewState[&amp;quot;Markers&amp;quot;] = Markers.ToArray();&lt;/p&gt;  &lt;p&gt;ViewState[&amp;quot;Paths&amp;quot;] = Paths.ToArray();&lt;/p&gt;  &lt;p&gt;ViewState[&amp;quot;Key&amp;quot;] = Key;&lt;/p&gt;  &lt;p&gt;ViewState[&amp;quot;AutomaticCenter&amp;quot;] = AutomaticCenter;&lt;/p&gt;  &lt;p&gt;ViewState[&amp;quot;AutomaticZoomLevel&amp;quot;] = AutomaticZoomLevel;&lt;/p&gt;  &lt;p&gt;return base.SaveViewState();&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;The only tricky thing was to save and load the markers and paths list based on a generic class. It may be a better way to do this, but I convert the list into an array and get it back to a list during the ViewState loading phase.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Using the WebControl in an ASPX Page&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;If you're a Web Designer or not so close to ASP.NET programming, you can now widely use the WebControl directly in an ASPX page.&lt;/p&gt;  &lt;p&gt;First, you need to register the WebControl in your page:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnVAu2qjvDI/AAAAAAAABCo/BVpir0-W_9w/s1600-h/clip_image002%5B15%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[15]" border="0" alt="clip_image002[15]" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnVAvptyZQI/AAAAAAAABCs/bN560VxLxu8/clip_image002%5B15%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;&amp;lt;%@ Register TagPrefix=&amp;quot;asp&amp;quot; Assembly=&amp;quot;GStaticMapTest&amp;quot;&lt;/p&gt;  &lt;p&gt;Namespace=&amp;quot;Initia.Google.GStaticMap&amp;quot; %&amp;gt;&lt;/p&gt;  &lt;p&gt;Then, you can show a simple map like this (don't forget runat=&amp;quot;server&amp;quot; and the center coordinate, since there are no markers and paths):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnVAwDo9ErI/AAAAAAAABCw/DZ56v3KfpnE/s1600-h/clip_image002%5B16%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[16]" border="0" alt="clip_image002[16]" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnVAxJBj_7I/AAAAAAAABC0/2j4l06yjYYY/clip_image002%5B16%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GStaticMap ID=&amp;quot;gsmTestMap&amp;quot; AutomaticZoomLevel=&amp;quot;true&amp;quot; AutomaticCenter=&amp;quot;true&amp;quot;&lt;/p&gt;  &lt;p&gt;Width=&amp;quot;320&amp;quot; Height=&amp;quot;200&amp;quot; Type=&amp;quot;RoadMap&amp;quot; ZoomLevel=&amp;quot;12&amp;quot; Key=&amp;quot;put_yours_here&amp;quot;&lt;/p&gt;  &lt;p&gt;runat=&amp;quot;server&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;Center Latitude=&amp;quot;45.759723&amp;quot; Longitude=&amp;quot;4.842223&amp;quot;&amp;gt;&amp;lt;/Center&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GStaticMap&amp;gt;&lt;/p&gt;  &lt;p&gt;As needed, you may add one or several markers (the center is optional if you use automatic center):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnVAx975N5I/AAAAAAAABC4/G6I5XXuorbk/s1600-h/clip_image002%5B17%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[17]" border="0" alt="clip_image002[17]" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnVAytPqy_I/AAAAAAAABC8/D1fGSVqcWYo/clip_image002%5B17%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GStaticMap ID=&amp;quot;gsmTestMap&amp;quot; AutomaticZoomLevel=&amp;quot;true&amp;quot; AutomaticCenter=&amp;quot;true&amp;quot;&lt;/p&gt;  &lt;p&gt;Width=&amp;quot;320&amp;quot; Height=&amp;quot;200&amp;quot; Type=&amp;quot;RoadMap&amp;quot; ZoomLevel=&amp;quot;12&amp;quot;&lt;/p&gt;  &lt;p&gt;Key=&amp;quot;put_yours_here&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;Center Latitude=&amp;quot;45.759723&amp;quot; Longitude=&amp;quot;4.842223&amp;quot;&amp;gt;&amp;lt;/Center&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;Markers&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GMarker Latitude=&amp;quot;45.859723&amp;quot; Longitude=&amp;quot;4.842223&amp;quot;&lt;/p&gt;  &lt;p&gt;Letter=&amp;quot;a&amp;quot; Color=&amp;quot;Red&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GMarker&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GMarker Latitude=&amp;quot;45.759723&amp;quot; Longitude=&amp;quot;5.042223&amp;quot;&lt;/p&gt;  &lt;p&gt;Letter=&amp;quot;b&amp;quot; Color=&amp;quot;Green&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GMarker&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GMarker Latitude=&amp;quot;45.659723&amp;quot; Longitude=&amp;quot;4.842223&amp;quot;&lt;/p&gt;  &lt;p&gt;Letter=&amp;quot;c&amp;quot; Color=&amp;quot;Blue&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GMarker&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GMarker Latitude=&amp;quot;45.759723&amp;quot; Longitude=&amp;quot;4.642223&amp;quot;&lt;/p&gt;  &lt;p&gt;Color=&amp;quot;Green&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GMarker&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/Markers&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GStaticMap&amp;gt;&lt;/p&gt;  &lt;p&gt;Finally, you may add one or several paths on your map:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnVAzJmRi1I/AAAAAAAABDA/5EHNI8qnj08/s1600-h/clip_image002%5B18%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[18]" border="0" alt="clip_image002[18]" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnVAz_KEN_I/AAAAAAAABDE/aM4f4qSRbZY/clip_image002%5B18%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GStaticMap ID=&amp;quot;gsmTestMap&amp;quot; AutomaticZoomLevel=&amp;quot;true&amp;quot; AutomaticCenter=&amp;quot;true&amp;quot;&lt;/p&gt;  &lt;p&gt;Width=&amp;quot;320&amp;quot; Height=&amp;quot;200&amp;quot; Type=&amp;quot;RoadMap&amp;quot; ZoomLevel=&amp;quot;12&amp;quot;&lt;/p&gt;  &lt;p&gt;Key=&amp;quot;put_yours_here&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;Center Latitude=&amp;quot;45.759723&amp;quot; Longitude=&amp;quot;4.842223&amp;quot;&amp;gt;&amp;lt;/Center&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;Markers&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GMarker Latitude=&amp;quot;45.859723&amp;quot;&lt;/p&gt;  &lt;p&gt;Longitude=&amp;quot;4.842223&amp;quot; Letter=&amp;quot;a&amp;quot; Color=&amp;quot;Red&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GMarker&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GMarker Latitude=&amp;quot;45.759723&amp;quot;&lt;/p&gt;  &lt;p&gt;Longitude=&amp;quot;5.042223&amp;quot; Letter=&amp;quot;b&amp;quot; Color=&amp;quot;Green&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GMarker&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GMarker Latitude=&amp;quot;45.659723&amp;quot;&lt;/p&gt;  &lt;p&gt;Longitude=&amp;quot;4.842223&amp;quot; Letter=&amp;quot;c&amp;quot; Color=&amp;quot;Blue&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GMarker&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GMarker Latitude=&amp;quot;45.759723&amp;quot;&lt;/p&gt;  &lt;p&gt;Longitude=&amp;quot;4.642223&amp;quot; Color=&amp;quot;Green&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GMarker&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/Markers&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;Paths&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GPath Color=&amp;quot;blue&amp;quot; Opacity=&amp;quot;255&amp;quot; Weight=&amp;quot;5&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;Points&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GCoordinate Latitude=&amp;quot;45.859723&amp;quot; Longitude=&amp;quot;4.842223&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GCoordinate&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GCoordinate Latitude=&amp;quot;45.759723&amp;quot; Longitude=&amp;quot;5.042223&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GCoordinate&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GCoordinate Latitude=&amp;quot;45.659723&amp;quot; Longitude=&amp;quot;4.842223&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GCoordinate&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/Points&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GPath&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GPath Color=&amp;quot;red&amp;quot; Opacity=&amp;quot;128&amp;quot; Weight=&amp;quot;5&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;Points&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GCoordinate Latitude=&amp;quot;45.659723&amp;quot; Longitude=&amp;quot;4.842223&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GCoordinate&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GCoordinate Latitude=&amp;quot;45.759723&amp;quot; Longitude=&amp;quot;4.642223&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GCoordinate&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GCoordinate Latitude=&amp;quot;45.859723&amp;quot; Longitude=&amp;quot;4.842223&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GCoordinate&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/Points&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GPath&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/Paths&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/asp:GStaticMap&amp;gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Using the WebControl in the Code-behind&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;If you love coding or have to programmatically manage static maps, you can use code-behind to fit your needs.&lt;/p&gt;  &lt;p&gt;The sample project included with this article shows you how to do this, here is some explanation about the basics.&lt;/p&gt;  &lt;p&gt;First, create an ASPX page and register the newly created WebControl:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnVA0sUSKMI/AAAAAAAABDI/cJSAal1qj_g/s1600-h/clip_image002%5B19%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[19]" border="0" alt="clip_image002[19]" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnVA1igO49I/AAAAAAAABDM/eWEc4l1pQZg/clip_image002%5B19%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;&amp;lt;%@ Register TagPrefix=&amp;quot;asp&amp;quot; Assembly=&amp;quot;GStaticMapTest&amp;quot;&lt;/p&gt;  &lt;p&gt;Namespace=&amp;quot;Initia.Google.GStaticMap&amp;quot; %&amp;gt;&lt;/p&gt;  &lt;p&gt;Now, &amp;quot;instantiate&amp;quot; the WebControl (this reference is automatically added in the designer if the ASPX page is right) where you want the static map to render:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnVA2dUkliI/AAAAAAAABDQ/ZjTAb3gCufk/s1600-h/clip_image002%5B20%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[20]" border="0" alt="clip_image002[20]" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnVA3LBezQI/AAAAAAAABDU/vURsMDtjudI/clip_image002%5B20%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;&amp;lt;asp:GStaticMap ID=&amp;quot;gsmTestMap&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&amp;lt;/asp:GStaticMap&amp;gt;&lt;/p&gt;  &lt;p&gt;At this point, you can set some attributes like automatic center, map type, width, height… and you &lt;b&gt;must&lt;/b&gt; set the Google API Key (beware: Google will serve you 1000 times the same static map per day and per IP address, you should use cache to avoid problems if you have some traffic !)&lt;/p&gt;  &lt;p&gt;To avoid prefixing GStaticMap components in the code-behind, use the following namespace:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnVA3-zbpXI/AAAAAAAABDY/hqNx5-7Na6k/s1600-h/clip_image002%5B21%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[21]" border="0" alt="clip_image002[21]" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnVA4j-qCPI/AAAAAAAABDc/Chf2g0kpMNg/clip_image002%5B21%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;using Initia.Google.GStaticMap;&lt;/p&gt;  &lt;p&gt;Then, you can show a simple map like this (don't forget the center coordinate, since there are no markers and paths):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnVA5rnASAI/AAAAAAAABDg/ZvUp3kLPBM4/s1600-h/clip_image002%5B22%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[22]" border="0" alt="clip_image002[22]" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnVA6VjLVoI/AAAAAAAABDk/w2ppFDnohDc/clip_image002%5B22%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Initialize map size&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;gsmTestMap.Width = int.Parse(tbMapWidth.Text);&lt;/p&gt;  &lt;p&gt;gsmTestMap.Height = int.Parse(tbMapHeight.Text);&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Set map type to Mobile&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;gsmTestMap.Type = GStaticMapType.Mobile;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Center the static map to my town: Lyon, FRANCE&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;gsmTestMap.Center.SetCoordinate(45.759722, 4.842222);&lt;/p&gt;  &lt;p&gt;gsmTestMap.Key = &amp;quot;put_yours_here&amp;quot;;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Set the zoom level&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;gsmTestMap.ZoomLevel = 8;&lt;/p&gt;  &lt;p&gt;As needed, you may add one or several markers (the center becomes optional if you use automatic center):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnVA7S2URmI/AAAAAAAABDo/UgSMOiZyzmk/s1600-h/clip_image002%5B23%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[23]" border="0" alt="clip_image002[23]" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnVA8TLPEqI/AAAAAAAABDs/uBTWDfybhFU/clip_image002%5B23%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;gsmTestMap.Markers.Add(new GMarker(45.759722, 4.842222, GMarkerColor.Blue, 'd');&lt;/p&gt;  &lt;p&gt;Finally, you may add one or several paths on your map like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnVA8xLS-uI/AAAAAAAABDw/nRCCXQbvuAQ/s1600-h/clip_image002%5B24%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002[24]" border="0" alt="clip_image002[24]" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnVA9xKwuOI/AAAAAAAABD0/1csgC-onyNg/clip_image002%5B24%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;// Trace a path from Lyon, FRANCE (45° 45&lt;i&gt;' 35? N, 4° 50' 32? E) to Paris, &lt;/i&gt;&lt;/p&gt;  &lt;p&gt;FRANCE (48° 51&lt;i&gt;' 23.68? N,&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;// 2° 21&lt;i&gt;' 6.58? E)&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;GPath fromLyonToParis = new GPath(KnownColor.Red, 5, 255);&lt;/p&gt;  &lt;p&gt;fromLyonToParis.Points.Add(new GCoordinate(45.759723, 4.842223));&lt;/p&gt;  &lt;p&gt;fromLyonToParis.Points.Add(new GCoordinate(48.856578, 2.351828));&lt;/p&gt;  &lt;p&gt;gsmTestMap.Paths.Add(fromLyonToParis);&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Points of Interest&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;This WebControl now covers all features of discontinued &lt;a href="http://www.codeproject.com/KB/webforms/GoogleMapData.aspx"&gt;MapData&lt;/a&gt; WebControl, using the official static maps API from Google.&lt;/p&gt;  &lt;p&gt;With this article, you learned how to:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;build a useful custom WebControl with attributes and children&lt;/li&gt;    &lt;li&gt;manage the ViewState&lt;/li&gt;    &lt;li&gt;use the Google Static Maps API&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;Known Limitations&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Missing visual designer&lt;/li&gt;    &lt;li&gt;Missing icon for the toolbox&lt;/li&gt; &lt;/ul&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-8231832511020214785?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/8231832511020214785/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2009/08/google-static-map-api-webcontrol.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/8231832511020214785'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/8231832511020214785'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2009/08/google-static-map-api-webcontrol.html' title='Google&amp;#39;s Static Map API WebControl'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_iuwZHhydmEs/SnVAQdtjHZI/AAAAAAAABAY/sczXoFWnOaA/s72-c/clip_image001_thumb%5B1%5D.gif?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-8865535615825578664</id><published>2009-08-02T00:24:00.001-07:00</published><updated>2009-08-02T00:24:36.050-07:00</updated><title type='text'>How to develop a Simple Vertical Text Scroller custom server control in ASP.NET</title><content type='html'>&lt;ul&gt;   &lt;li&gt;&lt;a href="http://download.ysatech.com/ASP_NET_Text_Scroller/"&gt;View this project in action &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://download.ysatech.com/ASP_NET_Text_Scroller/MyTextScroller.zip"&gt;Download source - 80 Kb&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;img alt="Sample Vertical Text Scroller" src="http://images.ysatech.com/textscroller/results.gif" width="290" height="110" /&gt;&lt;/p&gt;  &lt;h4&gt;Introduction&lt;/h4&gt;  &lt;p&gt;Couple years ago, I was looking for a simple text scroller application to replace our text scoller that was based on Java and I found the application Cross Browser marquee II on dynamicdrive.com. I have modified it to tailor my requirement. The main modification I made to the scroller was the addition of two buttons that controlled the flow of the vertical scroll content. Recently, I did a quick search on Google and found out that handful (50+) of websites were still using this application. Below are the few of them.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Check it out.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://cherryle.win.aplus.net/index.asp"&gt;http://cherryle.win.aplus.net/index.asp&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://www.hydroqual.com/"&gt;http://www.hydroqual.com&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://www.sabugacenter.com/"&gt;http://www.sabugacenter.com&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://www.ehub.si/"&gt;http://www.ehub.si&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://www.globalnews-indonesia.com/"&gt;http://www.globalnews-indonesia.com&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://www.mmtv.co.za/index.htm"&gt;http://www.mmtv.co.za/index.htm&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://www.opcfoundation.org/"&gt;http://www.opcfoundation.org&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Moving forward, I have converted this application to ASP.NET custom server control. Now, the ASP.NET developers can drag and drop the control to the page without copy and paste between the web applications. Below is a step by step tutorial on how I have accomplished this. Hope this tutorial will give someone an idea on how to create a custom server control.&lt;/p&gt;  &lt;h4&gt;Download the original application/ script&lt;/h4&gt; &lt;a href="http://www.dynamicdrive.com/dynamicindex2/cmarquee2.htm"&gt;cmarquee2.htm&lt;/a&gt;  &lt;h4&gt;Note&lt;/h4&gt;  &lt;p&gt;I have broken the cmarquee2.htm page into three different sections, namely &lt;strong&gt;Style Sheet&lt;/strong&gt;, &lt;strong&gt;JavaScript&lt;/strong&gt; and &lt;strong&gt;static HTML elements/ tags&lt;/strong&gt;.&lt;/p&gt;  &lt;h4&gt;Create Class Library&lt;/h4&gt;  &lt;ol&gt;   &lt;li&gt;     &lt;p&gt;Open VS 2005/2008. Go to File, New, Project, Visual C# and select Class Library template and fill up the required field.&lt;/p&gt;      &lt;p&gt;&lt;img alt="New Project" src="http://images.ysatech.com/textscroller/New_Project.gif" /&gt;&lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;     &lt;p&gt;Rename the class1.cs to &lt;strong&gt;TextScroller.cs&lt;/strong&gt;&lt;/p&gt;   &lt;/li&gt; &lt;/ol&gt;  &lt;h4&gt;Adding Style Sheet&lt;/h4&gt;  &lt;p&gt;Right click the project, Add, New Item, Visual C# Project Items, Select Style Sheet from the available templates. I named it &lt;strong&gt;TextScroller.css&lt;/strong&gt;. Extract all the Style Sheet from &lt;strong&gt;cmarquee2.htm&lt;/strong&gt; into &lt;strong&gt;TextScroller.css&lt;/strong&gt;&lt;/p&gt;  &lt;h4&gt;Adding JavaScript&lt;/h4&gt;  &lt;p&gt;Right click the project, Add, New Item, Visual C# Project Items, Select Jscript from the available templates. I named it &lt;strong&gt;TextScroller.js&lt;/strong&gt;. Extract all the JavaScript from &lt;strong&gt;cmarquee2.htm&lt;/strong&gt; into &lt;strong&gt;TextScroller.js&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;img alt="Add New Item" src="http://images.ysatech.com/textscroller/AddNewItem.gif" /&gt;&lt;/p&gt;  &lt;h4&gt;Adding New Folder&lt;/h4&gt;  &lt;p&gt;Right click the MyTextScroller project, Add, New Folder, rename the folder to images. Place all the images in this folder.&lt;/p&gt;  &lt;h4&gt;Adding System.Web References&lt;/h4&gt;  &lt;p&gt;Right click on the MyTextScroller project, Add Reference. In the .NET tab locate the System.Web component name, select it and click Ok.&lt;/p&gt;  &lt;p&gt;&lt;img alt="Adding Web.System Reference" src="http://images.ysatech.com/textscroller/AddingReferences.gif" /&gt;&lt;/p&gt;  &lt;h4&gt;Check Point&lt;/h4&gt;  &lt;p&gt;The structure of the project should look like the picture from below if you follow all the above step correctly.&lt;/p&gt;  &lt;p&gt;&lt;img alt="Project Structure" src="http://images.ysatech.com/textscroller/Project_Structure1.gif" /&gt;&lt;/p&gt;  &lt;h4&gt;Embedding the Resources&lt;/h4&gt;  &lt;p&gt;Right click one of the images, select Properties, and change the Build Action value from Content to Embedded Resource. Repeat the same step for all the other images.&lt;/p&gt;  &lt;p&gt;&lt;img alt="Embed Images" src="http://images.ysatech.com/textscroller/embed_images.gif" /&gt;&lt;/p&gt;  &lt;p&gt;Repeat the above step for the JavaScript and Style Sheet.&lt;/p&gt;  &lt;p&gt;Double click the AssemblyInfo.cs. Add the following to the bottom of the file.&lt;/p&gt;  &lt;p&gt;&lt;img src="http://www.codeproject.com/images/minus.gif" width="9" height="9" /&gt; Collapse&lt;/p&gt;  &lt;pre&gt;[assembly: System.Web.UI.WebResource(&amp;quot;MyTextScroller.TextScroller.css&amp;quot;, &amp;quot;text/css&amp;quot;)]&lt;br /&gt;[assembly: System.Web.UI.WebResource(&amp;quot;MyTextScroller.TextScroller.js&amp;quot;, &amp;quot;text/javascript&amp;quot;)]&lt;br /&gt;[assembly: System.Web.UI.WebResource(&amp;quot;MyTextScroller.images.nav-arrow-down-hover.gif&amp;quot;, &amp;quot;image/gif&amp;quot;)]&lt;br /&gt;[assembly: System.Web.UI.WebResource(&amp;quot;MyTextScroller.images.nav-arrow-down.gif&amp;quot;, &amp;quot;image/gif&amp;quot;)]&lt;br /&gt;[assembly: System.Web.UI.WebResource(&amp;quot;MyTextScroller.images.nav-arrow-up-hover.gif&amp;quot;, &amp;quot;image/gif&amp;quot;)]&lt;br /&gt;[assembly: System.Web.UI.WebResource(&amp;quot;MyTextScroller.images.nav-arrow-up.gif&amp;quot;, &amp;quot;image/gif&amp;quot;)]&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Note&lt;/h4&gt;&lt;br /&gt;&lt;img alt="Default Namespace" src="http://images.ysatech.com/textscroller/defaultNamespace.gif" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The syntax - [assembly: System.Web.UI.WebResource(&amp;quot;Default Namespace&lt;strong&gt;.&lt;/strong&gt;File Location&lt;strong&gt;.&lt;/strong&gt;File Name&amp;quot;, &amp;quot;Type&amp;quot;)]&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Example 1&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;My Default Name Space is &lt;strong&gt;MyTextScroller&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;My JavaScript File name is &lt;strong&gt;TextScroller.js&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;And I'll end up having this line in my AssemblyInfo.cs&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img src="http://www.codeproject.com/images/minus.gif" width="9" height="9" /&gt; Collapse&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;[assembly: System.Web.UI.WebResource(&amp;quot;MyTextScroller.TextScroller.js&amp;quot;, &amp;quot;text/javascript&amp;quot;)]&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Example 2&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;My Default Name Space is &lt;strong&gt;MyTextScroller&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;All my images are in images folder&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;My image name is &lt;strong&gt;nav-arrow-down-hover.gif &lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;And I’ll end up having this line in my AssemblyInfo.cs&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img src="http://www.codeproject.com/images/minus.gif" width="9" height="9" /&gt; Collapse&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;[assembly: System.Web.UI.WebResource(&amp;quot;MyTextScroller.images.nav-arrow-down.gif&amp;quot;, &amp;quot;image/gif&amp;quot;)]&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;TextScroller.cs&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The &lt;strong&gt;TextScroller.cs&lt;/strong&gt; will hold all the static HTML elements in the cmarquee2.htm. Please look at the code, is pretty straight forward. Here is a brief explanation.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Add design-time attributes to provide custom metadata that will be used to display the control in the visual designer at design time&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img src="http://www.codeproject.com/images/minus.gif" width="9" height="9" /&gt; Collapse&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;namespace MyTextScroller&lt;br /&gt;{&lt;br /&gt;    [   AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal),&lt;br /&gt;        AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal),&lt;br /&gt;        ParseChildren(true, &amp;quot;innerHTML&amp;quot;),&lt;br /&gt;        DefaultProperty(&amp;quot;innerHTML&amp;quot;),&lt;br /&gt;        ToolboxData(&amp;quot;&amp;lt;{0}:TextScroller runat=&amp;quot;\&amp;quot;&amp;quot;server\&amp;quot;&amp;gt; &amp;quot;) ]&lt;br /&gt;    public class TextScroller : WebControl, INamingContainer&lt;br /&gt;	{&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Additional Reading/ Information&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The ToolboxData attribute specifies the default tag generated for the TextScroller control when it is dragged from the Toolbox into a page at design time.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.parsechildrenattribute.aspx"&gt;ParseChildren&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.web.aspnethostingpermission.aspx"&gt;AspNetHostingPermission&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;//Properties to adjust the width and height of the div and set the innerHTML od the div&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img src="http://www.codeproject.com/images/minus.gif" width="9" height="9" /&gt; Collapse&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;     #region Public Properties&lt;br /&gt;&lt;br /&gt;        private Unit width = Unit.Pixel(260);&lt;br /&gt;        public override Unit Width&lt;br /&gt;        {&lt;br /&gt;            get { return width; }&lt;br /&gt;            set { EnsureChildControls(); width = value; }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private Unit height = Unit.Pixel(160);&lt;br /&gt;        public override Unit Height&lt;br /&gt;        {&lt;br /&gt;            get { return height; }&lt;br /&gt;            set { EnsureChildControls(); height = value; }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;//property to set the content of the Text Scroller&lt;br /&gt;private string _innerHTML = &amp;quot;Your Content here&amp;quot;;&lt;br /&gt;&lt;br /&gt;        [   Browsable(true), //display this property in designer&lt;br /&gt;            Category(&amp;quot;Appearance&amp;quot;),&lt;br /&gt;            DefaultValue(&amp;quot;Your Content Here&amp;quot;),&lt;br /&gt;            Description(&amp;quot;The Content to Display.&amp;quot;),&lt;br /&gt;            Localizable(true),&lt;br /&gt;            PersistenceMode(PersistenceMode.InnerDefaultProperty) ]&lt;br /&gt;        public virtual string innerHTML&lt;br /&gt;        {&lt;br /&gt;            get&lt;br /&gt;            {&lt;br /&gt;                return _innerHTML;&lt;br /&gt;            }&lt;br /&gt;            set&lt;br /&gt;            {&lt;br /&gt;                EnsureChildControls(); _innerHTML = value; &lt;br /&gt;            }&lt;br /&gt;        }	&lt;br /&gt;        #endregion&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Working with Web Resources in ASP.NET 2.0&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Example - Images&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img src="http://www.codeproject.com/images/minus.gif" width="9" height="9" /&gt; Collapse&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;Image myImage = new Image();&lt;br /&gt;ClientScriptManager cs = Page.ClientScript;&lt;br /&gt;Type rsType = this.GetType();&lt;br /&gt;myImage.ImageUrl = cs.GetWebResourceUrl(rsType, &amp;quot;MyTextScroller.images.nav-arrow-up.gif&amp;quot;)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Example - JavaScript&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img src="http://www.codeproject.com/images/minus.gif" width="9" height="9" /&gt; Collapse&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;Type rsType = this.GetType();&lt;br /&gt;this.Page.ClientScript.RegisterClientScriptInclude(&lt;br /&gt;rsType, &amp;quot;TextScroller_Script_Name&amp;quot;,&lt;br /&gt;Page.ClientScript.GetWebResourceUrl(rsType, &amp;quot; MyTextScroller.TextScroller.js&amp;quot;));&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Example - Style Sheets&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img src="http://www.codeproject.com/images/minus.gif" width="9" height="9" /&gt; Collapse&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;   &lt;br /&gt;Type rsType = this.GetType();     &lt;br /&gt;string csslink = &amp;quot;&amp;lt;link rel='stylesheet' type='text/css' href='&amp;quot; + &lt;br /&gt;	Page.ClientScript.GetWebResourceUrl(rsType, &amp;quot;MyTextScroller.TextScroller.css&amp;quot;) + &amp;quot;' /&amp;gt;&amp;quot;;&lt;br /&gt;LiteralControl include = new LiteralControl(csslink);&lt;br /&gt;this.Page.Header.Controls.Add(include);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;//using the embeded JavaScript and Style Sheet&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img src="http://www.codeproject.com/images/minus.gif" width="9" height="9" /&gt; Collapse&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  &lt;br /&gt;        protected override void OnInit(EventArgs e)&lt;br /&gt;        {&lt;br /&gt;            //Get the name of the Web Resource.&lt;br /&gt;            base.OnInit(e);&lt;br /&gt;&lt;br /&gt;            this.Page.ClientScript.RegisterClientScriptInclude(&lt;br /&gt;                        this.GetType(), &amp;quot;TextScroller&amp;quot;,&lt;br /&gt;                        Page.ClientScript.GetWebResourceUrl(this.GetType(),&lt;br /&gt;                        &amp;quot;Scroller.TextScroller.js&amp;quot;));&lt;br /&gt;&lt;br /&gt;            // create the style sheet control and put it in the document header&lt;br /&gt;            string csslink = @&amp;quot;&amp;lt;link rel='stylesheet' type='text/css' href='&amp;quot; + &lt;br /&gt;				Page.ClientScript.GetWebResourceUrl(this.GetType(), &amp;quot;Scroller.TextScroller.css&amp;quot;) + &amp;quot;' /&amp;gt;&amp;quot;;&lt;br /&gt;            LiteralControl include = new LiteralControl(csslink);&lt;br /&gt;&lt;br /&gt;            this.Page.Header.Controls.Add(include);&lt;br /&gt;        }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;//write the output to the page that are in the cmarquee2.htm page&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img src="http://www.codeproject.com/images/minus.gif" width="9" height="9" /&gt; Collapse&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;		protected override void OnPreRender(EventArgs e)&lt;br /&gt;        {&lt;br /&gt;            base.OnPreRender(e);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        protected override void Render(HtmlTextWriter output)&lt;br /&gt;        {&lt;br /&gt;            EnsureChildControls(); &lt;br /&gt;            output.Write(GenerateDiv());&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;//create all the HTML Tag elemets&lt;br /&gt;        private string GenerateDiv()&lt;br /&gt;        {&lt;br /&gt;			StringBuilder b = new StringBuilder();&lt;br /&gt;            ClientScriptManager cs = Page.ClientScript;&lt;br /&gt;            Type rsType = this.GetType();&lt;br /&gt;			&lt;br /&gt;			b.Append(&amp;quot;&amp;lt;div style=\&amp;quot;width:&amp;quot;);&lt;br /&gt;            b.Append(width.Value);&lt;br /&gt;			&lt;br /&gt;            //see attached code ...&lt;br /&gt;			....&lt;br /&gt;         	return b.ToString();&lt;br /&gt;        }&lt;br /&gt;		&lt;br /&gt;		protected override void CreateChildControls()&lt;br /&gt;        {&lt;br /&gt;            Controls.Clear();&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        protected override void OnLoad(EventArgs e)&lt;br /&gt;        {&lt;br /&gt;            base.OnLoad(e); &lt;br /&gt;        }    &lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Individualizing the Control: Add a custom toolbox icon for the control&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;  &lt;li&gt;Create an icon from any of the links below. This is free.&lt;br /&gt;    &lt;br /&gt;&lt;a href="http://tools.dynamicdrive.com/favicon/"&gt;dynamicdrive&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;&lt;a href="http://genfavicon.com/"&gt;genfavicon&lt;/a&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;What is the name of your class? For instance my class name is &lt;strong&gt;TextScroller&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;    &lt;p&gt;&lt;img src="http://www.codeproject.com/images/minus.gif" width="9" height="9" /&gt; Collapse&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;    &lt;pre&gt;public class TextScroller : WebControl, INamingContainer&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;    &lt;p&gt;Then I named the icon &lt;strong&gt;TextScroller.ico&lt;/strong&gt;. Place it in the project root directory and change the Build Action to &lt;strong&gt;Embeded Resource&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;img alt="Embed Icon" src="http://images.ysatech.com/textscroller/embed_images2.gif" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Adding the Control to the Toolbox&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;  &lt;li&gt;&lt;br /&gt;    &lt;p&gt;Go to View, Toolbox, Right click any place in the Toolbox, Add Tab, I name it MyTextScroller.&lt;/p&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;br /&gt;    &lt;p&gt;Right click MyTextScroller, Choose Items, .NET Framework Components Tab, Browse, find the MyTextScroller.dll, click Ok.&lt;/p&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;br /&gt;    &lt;p&gt;You should see something like this on the Toolbox.&lt;/p&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;img alt="Toolbox Icon" src="http://images.ysatech.com/textscroller/toolbox_icon.gif" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;How to test it? / Using the code&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Add Refenence&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;  &lt;li&gt;Right click on the solution, Add, New Web Site, ASP.NET Web Site/ ASP.NET AJAX-Enabled Web Site&lt;br /&gt;    &lt;br /&gt;&lt;img alt="Add New Website" src="http://images.ysatech.com/textscroller/AddNewWebSite.gif" /&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;Right click the TestMyTextScroller, Add References, Project Tab, MyTextScroller project, Ok.&lt;br /&gt;    &lt;br /&gt;&lt;img alt="Add Reference" src="http://images.ysatech.com/textscroller/AddingReferences2.gif" /&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Drag the TextScroller from the Toolbox to the Default.aspx. Try one of the following&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img src="http://www.codeproject.com/images/minus.gif" width="9" height="9" /&gt; Collapse&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;cc1:TextScroller ID=&amp;quot;TextScroller1&amp;quot; runat=&amp;quot;server&amp;quot; Height=&amp;quot;100px&amp;quot;&amp;gt;&lt;br /&gt;		My test content here. &lt;br /&gt;&lt;br /&gt;		&lt;a href="http://www.codeproject.com/&amp;lt;span"&gt;&amp;quot;http://blog.ysatech.com/&amp;quot; target=&amp;quot;_blank&amp;quot;&amp;gt;My Blog&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;		More text here….&lt;br /&gt;      &amp;lt;/cc1:TextScroller&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Or&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img src="http://www.codeproject.com/images/minus.gif" width="9" height="9" /&gt; Collapse&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;    {&lt;br /&gt;         TextScrollerContent();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    internal void TextScrollerContent()&lt;br /&gt;    {&lt;br /&gt;        StringBuilder sbContent = new StringBuilder(string.Empty);&lt;br /&gt;        &lt;br /&gt;        sbContent.Append(&amp;quot;My test content here. &amp;lt;br /&amp;gt;&amp;quot;);&lt;br /&gt;        sbContent.Append(&amp;quot;&amp;lt;a href=\&amp;quot;http://blog.ysatech.com\&amp;quot;&amp;gt;My Blog &amp;lt;br /&amp;gt;&amp;quot;);&lt;br /&gt;        sbContent.Append(&amp;quot;More text here…&amp;quot;);    &lt;br /&gt;      &lt;br /&gt;        TextScroller1.innerHTML = sbContent.ToString();&lt;br /&gt;    }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;You should see something like below:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img alt="Results" src="http://images.ysatech.com/textscroller/results.gif" /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Points of Interest&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Do not use any custom server control from any unknown sources that have JavaScript embedded to it. Go through all the JavaScript and make sure that no potential malicious scripts embedded in it.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Next improvement:&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;  &lt;li&gt;&lt;br /&gt;    &lt;p&gt;Support multiple instances, currently this version work only with one instance of the TextScroller on the &lt;strong&gt;same page&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;br /&gt;    &lt;p&gt;Allow user to change the image button during design time&lt;/p&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;Conclusion&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Here are the lists of items we have covered in this article:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;  &lt;li&gt;&lt;br /&gt;    &lt;p&gt;How to create a Custom Server Control&lt;/p&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;br /&gt;    &lt;p&gt;How to embed resources&lt;/p&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;br /&gt;    &lt;p&gt;How to access embedded Resource&lt;/p&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;br /&gt;    &lt;p&gt;How to include custom toolbox icon&lt;/p&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;&lt;br /&gt;    &lt;p&gt;How to test the new control&lt;/p&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;References&lt;/h4&gt;&lt;br /&gt;&lt;a href="http://aspalliance.com/726"&gt;http://aspalliance.com/726 &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.dynamicdrive.com/dynamicindex2/cmarquee2.htm"&gt;http://www.dynamicdrive.com/dynamicindex2/cmarquee2.htm &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.codeproject.com/"&gt;http://www.codeproject.com/ &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.ensurechildcontrols.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.web.ui.control.ensurechildcontrols.aspx &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.web.aspnethostingpermission.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.web.aspnethostingpermission.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://ondotnet.com/pub/a/dotnet/excerpt/progaspdotnet_14/index2.html"&gt;http://ondotnet.com/pub/a/dotnet/excerpt/progaspdotnet_14/index2.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.web.ui.parsechildrenattribute.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.web.ui.parsechildrenattribute.aspx&lt;/a&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-8865535615825578664?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/8865535615825578664/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2009/08/how-to-develop-simple-vertical-text.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/8865535615825578664'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/8865535615825578664'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2009/08/how-to-develop-simple-vertical-text.html' title='How to develop a Simple Vertical Text Scroller custom server control in ASP.NET'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-7277620368594576703</id><published>2009-08-01T07:14:00.001-07:00</published><updated>2009-08-01T07:14:50.540-07:00</updated><title type='text'>Split Strings Using XML</title><content type='html'>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;This article would help developers looking to split strings in a single query using XML. We generally use a user defined function, which you all may have found at many places that splits the string based on the delimiter passed. But, when it comes to separate the string in a single query without any help of user defined function we often get panic. I have found a much optimized and shorter way of splitting any string based on the delimiter passed. I will be using the power of XML to do the same.&lt;/p&gt;  &lt;p&gt;Let's say for example there is a string 'A,B,C,D,E' and I want to split it based on the delimiter ','. The first step would be to convert that string into XML, replacing the delimiter with some start and end XML tag.&lt;/p&gt;  &lt;p&gt;Declare @xml as xml,@str as varchar(100),@delimiter as varchar(10)   &lt;br /&gt;SET @str='A,B,C,D,E'    &lt;br /&gt;SET @delimiter =','    &lt;br /&gt;SET @xml = cast(('&amp;lt;X&amp;gt;'+replace(@str,@delimiter ,'&amp;lt;/X&amp;gt;&amp;lt;X&amp;gt;')+'&amp;lt;/X&amp;gt;') as xml)&lt;/p&gt;  &lt;p&gt;Here as shown above, the delimiter ',' is replaced by &amp;lt;/X&amp;gt;&amp;lt;X&amp;gt; tags.   &lt;br /&gt;When you will see the output after converting the string into XML, you will be able to see the string as shown in the image below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://1.bp.blogspot.com/_4PCltNyUraU/SkZTtsBWwjI/AAAAAAAAAAM/5OJHOzm61C0/s1600-h/3623.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image001" border="0" alt="clip_image001" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnRNy6RuC3I/AAAAAAAABAE/RtyXdbr5ZvM/clip_image001%5B3%5D.jpg?imgmax=800" width="99" height="101" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Once the string is converted into XML you can easily query that using XQuery.   &lt;br /&gt;SELECT N.value('.', 'varchar(10)') as value FROM @xml.nodes('X') as T(N)&lt;/p&gt;  &lt;p&gt;This will give the output as a separated string as:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://3.bp.blogspot.com/_4PCltNyUraU/SkZTt8FL8bI/AAAAAAAAAAU/VxQORAGdzLU/s1600-h/3624.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnRNzw3U9BI/AAAAAAAABAI/6HC8KHLKs7U/clip_image002%5B3%5D.jpg?imgmax=800" width="94" height="124" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now, say if I have a table as having an ID column and comma separated string as data column.&lt;/p&gt;  &lt;p&gt;DECLARE @t TABLE( ID INT IDENTITY, data VARCHAR(50))&lt;/p&gt;  &lt;p&gt;INSERT INTO @t(data) SELECT 'AA,AB,AC,AD'   &lt;br /&gt;INSERT INTO @t(data) SELECT 'BA,BB,BC'&lt;/p&gt;  &lt;p&gt;I can use the method shown above to split the string.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://3.bp.blogspot.com/_4PCltNyUraU/SkZTuKw2JdI/AAAAAAAAAAc/LkO-ud5eMiM/s1600-h/3662.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image003" border="0" alt="clip_image003" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnRN0yS6IsI/AAAAAAAABAM/iiqPNXIOSOs/clip_image003%5B3%5D.jpg?imgmax=800" width="153" height="71" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;select F1.id,&lt;/p&gt;  &lt;p&gt;F1.data,   &lt;br /&gt;O.splitdata    &lt;br /&gt;from    &lt;br /&gt;(    &lt;br /&gt;select *,    &lt;br /&gt;cast('&amp;lt;X&amp;gt;'+replace(F.data,',','&amp;lt;/X&amp;gt;&amp;lt;X&amp;gt;')+'&amp;lt;/X&amp;gt;' as XML) as xmlfilter    &lt;br /&gt;from @t F    &lt;br /&gt;)F1    &lt;br /&gt;cross apply    &lt;br /&gt;(    &lt;br /&gt;select fdata.D.value('.','varchar(50)') as splitdata    &lt;br /&gt;from f1.xmlfilter.nodes('X') as fdata(D)) O&lt;/p&gt;  &lt;p&gt;First of all, cast the 'data' column of table @t into XML data type by replacing the delimiter by starting and ending tags   &lt;br /&gt;'&amp;lt;X&amp;gt;&amp;lt;/X&amp;gt;'.&lt;/p&gt;  &lt;p&gt;I have used 'CROSS APPLY' for splitting the data. APPLY clause let's you join a table to a table-valued-function. The APPLY clause acts like a JOIN without the ON clause comes in two flavors:&lt;/p&gt;  &lt;p&gt;&lt;b&gt;CROSS and OUTER&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The OUTER APPLY clause returns all the rows on the left side (@t) whether they return any rows in the table-valued-function or not. The columns that the table-valued-function returns are null if no rows are returned.&lt;/p&gt;  &lt;p&gt;The CROSS APPLY only returns rows from the left side (@t) if the table-valued-function returns rows.&lt;/p&gt;  &lt;p&gt;Executing the select statement mentioned above would display the following output:&lt;a href="http://3.bp.blogspot.com/_4PCltNyUraU/SkZTuMs243I/AAAAAAAAAAk/8WMJC3NYOrI/s1600-h/3663.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnRN2LFtIdI/AAAAAAAABAQ/NQQSmZiMX1I/clip_image004%5B3%5D.jpg?imgmax=800" width="200" height="158" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This article might have made you clear of the power of XML and a very good use of 'CROSS APPLY'. There are other options to split strings in a single query using recursive CTEs.&lt;/p&gt;  &lt;p&gt;Now whenever splitting of string is required you can easily cast the string into XML, by replacing the delimiter by XML start and end tags and then use the method shown above to split the string.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-7277620368594576703?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/7277620368594576703/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2009/08/split-strings-using-xml.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/7277620368594576703'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/7277620368594576703'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2009/08/split-strings-using-xml.html' title='Split Strings Using XML'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_iuwZHhydmEs/SnRNy6RuC3I/AAAAAAAABAE/RtyXdbr5ZvM/s72-c/clip_image001%5B3%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-2555675350898847549</id><published>2009-07-31T05:39:00.001-07:00</published><updated>2009-07-31T05:39:01.691-07:00</updated><title type='text'>Provider Design Patterns in NET 2.0</title><content type='html'>&lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.codeproject.com/KB/architecture/ProviderDesignPattern/ProviderDesignPattern.zip"&gt;Download ProviderDesignPattern.zip - 4.01 MB&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.codeproject.com/KB/architecture/ProviderDesignPattern.aspx"&gt;Source Article&lt;/a&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Introduction&lt;/li&gt;    &lt;li&gt;What are the benefits of the article ?&lt;/li&gt;    &lt;li&gt;Application Architecture&lt;/li&gt;    &lt;li&gt;Application Configuration&lt;/li&gt;    &lt;li&gt;Provider Implementation&lt;/li&gt;    &lt;li&gt;Restoring Database&lt;/li&gt;    &lt;li&gt;Debugging code&lt;/li&gt;    &lt;li&gt;Conclusion&lt;/li&gt;    &lt;li&gt;References&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Provider Design Pattern is a new pattern that Microsoft formalized in ASP.NET Whidbey. The pattern was officially named in the summer of 2002 when Microsoft was designing Whidbey's new Personalization feature.   &lt;br /&gt;&lt;b&gt;Benefits of Provider&lt;/b&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;No need to explicitly instantiate classes. The .NET framework will automatically manage class instantiation, including re-using classes that have already been instantiated. This will greatly improve the memory management of your application.&lt;/li&gt;    &lt;li&gt;Switching data sources is much easier. Changing the source of data for your application from the current database to any database, whether SQL Server, Oracle, XML, or other, is a simple as replacing your existing concrete (implementer) class with a new concrete (implementer) class and inheriting from your provider class. That is all. Your presentation and business logic layers remain unchanged, thereby reducing effort required to switch data sources and the amount of regression testing required thereafter.&lt;/li&gt;    &lt;li&gt;Learning the Provider Design concept will make it very easy to customize built-in .NET framework providers.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;A provider implementation must derive from an abstract base class, which is used to define a contract for a particular feature.   &lt;br /&gt;For example, to create a Person provider for SQL, you create a new class &lt;b&gt;SqlPersonProvider&lt;/b&gt;, which derives from &lt;b&gt;PersonProvider&lt;/b&gt;. The base class of PersonProvider is &lt;b&gt;ProviderBase&lt;/b&gt; . The &lt;b&gt;ProviderBase&lt;/b&gt; class is used to mark implementers as a provider and forces the implementation of a required method and property common to all providers.    &lt;br /&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnLkuUUUdZI/AAAAAAAAA7I/D8iPDLOkca0/s1600-h/clip_image002%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnLkvPSF6bI/AAAAAAAAA7M/dPJACdIBmYY/clip_image002_thumb%5B1%5D.jpg?imgmax=800" width="571" height="131" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;What are the benefits of the article ?&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;- Understanding the implementation of Provider Design Pattern   &lt;br /&gt;- Understanding the implementation of 3-tier architecture application    &lt;br /&gt;- Understanding the application architecture    &lt;br /&gt;- Naming Conventions&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Note: &lt;/b&gt;I strongly suggest that you use the exact names that I use in this document to develop your solution for the purpose of learning this concept. Once you have tested and understand how it works, then you can integrate your own naming conventions.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Application Implementation&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;I developed an application, Phone Book, as desktop application to describe the provider idea.   &lt;br /&gt;The phone book application was developed with the use of 3 tier architecture as shown on application architecture.    &lt;br /&gt;Database objects like tables, fields and stored procedures are represented by object oriented classes, properties and methods on the provider infos of CompanyName library    &lt;br /&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnLkwdLW21I/AAAAAAAAA7Q/QWjpRirwjYY/s1600-h/clip_image003%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image003" border="0" alt="clip_image003" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnLkxtLyRmI/AAAAAAAAA7U/0HVS5UBr6q0/clip_image003_thumb%5B1%5D.jpg?imgmax=800" width="465" height="425" /&gt;&lt;/a&gt;    &lt;br /&gt;The presentation layer calls the result from business logic layer and then data retrieved from database by the use of providers implemented at data access layer library.    &lt;br /&gt;&lt;b&gt;Solution Projects [ 4 Projects]:&lt;/b&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;b&gt;BusinessLogicLayer : &lt;/b&gt;The business logic layer of the application&lt;/li&gt;    &lt;li&gt;&lt;b&gt;CompanyName: &lt;/b&gt;it includes the global classes to all solution's projects&lt;/li&gt;    &lt;li&gt;&lt;b&gt;DataAccessLayer: &lt;/b&gt;The data access layer of the application&lt;/li&gt;    &lt;li&gt;&lt;b&gt;PhoneBookApplication: &lt;/b&gt;The presentation layer&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnLkyeKs68I/AAAAAAAAA7Y/Ozrz7N13H3w/s1600-h/clip_image005%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image005" border="0" alt="clip_image005" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnLkz4ZLgxI/AAAAAAAAA7c/2mn0fDsvfz4/clip_image005_thumb%5B1%5D.jpg?imgmax=800" width="557" height="345" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Application Architecture&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The following figure depicts the common tiers of a distributed application. This document distinguishes between business data and the business processes that use the data; the business process tier is discussed only where needed for clarification. Likewise, the presentation tier is discussed only where there are direct implications for the way data is represented, such as the way Microsoft® ASP.NET Web pages expose business data.&amp;#160; &lt;a href="http://msdn.microsoft.com/en-us/library/ms978496.aspx"&gt;Read More&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnLk0s-4BxI/AAAAAAAAA7g/HVfWNe7yBAo/s1600-h/clip_image007%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image007" border="0" alt="clip_image007" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnLk1k7ueSI/AAAAAAAAA7k/f0eo4EKHZyg/clip_image007_thumb%5B1%5D.jpg?imgmax=800" width="436" height="410" /&gt;&lt;/a&gt;    &lt;br /&gt;the following diagram describes the architecture of all solution's projects:    &lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnLk3qsaaCI/AAAAAAAAA7o/EScS4l-op-o/s1600-h/clip_image009%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image009" border="0" alt="clip_image009" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnLk6w2NWKI/AAAAAAAAA7s/DS1Nc7-E-H8/clip_image009_thumb%5B1%5D.jpg?imgmax=800" width="553" height="345" /&gt;&lt;/a&gt;    &lt;br /&gt;The following diagram, ERD, is the database design of phonebook    &lt;br /&gt;&lt;a href="http://www.codeproject.com/KB/architecture/$image40.png"&gt;     &lt;br /&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image011" border="0" alt="clip_image011" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnLk7sdYh_I/AAAAAAAAA7w/Y64EAa-HFOw/clip_image011%5B4%5D.jpg?imgmax=800" width="544" height="438" /&gt;&lt;/a&gt;    &lt;br /&gt;The following diagram, &lt;b&gt;Use-Case diagram&lt;/b&gt;, describe the main functionality of the application:    &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnLk8ZStE8I/AAAAAAAAA70/LTfaHqlH1PY/s1600-h/clip_image013%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image013" border="0" alt="clip_image013" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnLk9KcN4bI/AAAAAAAAA74/BOLZ6nBJIHA/clip_image013_thumb%5B1%5D.jpg?imgmax=800" width="476" height="415" /&gt;&lt;/a&gt;    &lt;br /&gt;Now, we can discuss the implementation of each project:    &lt;br /&gt;&lt;b&gt;(1) &lt;/b&gt;Open Visual Studio 2005    &lt;br /&gt;1- Create Windows Application and name it &lt;b&gt;PhoneBookApplication&lt;/b&gt;    &lt;br /&gt;2- Choose File Menu --&amp;gt; Add --&amp;gt; New Project and name it &lt;b&gt;BusinessLogicLayer &lt;/b&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;&lt;b&gt;3- &lt;/b&gt;Choose File Menu --&amp;gt; Add --&amp;gt; New Project and name it &lt;b&gt;DataAccessLayer &lt;/b&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;&lt;b&gt;4- &lt;/b&gt;Choose File Menu --&amp;gt; Add --&amp;gt; New Project and name it &lt;b&gt;CompanyName CompanyName :&lt;/b&gt;    &lt;br /&gt;this project will include common libraries that are globally used in the development and shared objects among projects    &lt;br /&gt;so you will add reference for &lt;b&gt;CompanyName&lt;/b&gt; library to all other applications.    &lt;br /&gt;ex. i created the provider info classes to be shared among the &amp;quot;BussinessLogicLayer&amp;quot; and &amp;quot;DataAccessLayer&amp;quot; projects    &lt;br /&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnLk-BEV-bI/AAAAAAAAA78/-pNNZFaBdFw/s1600-h/clip_image015%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image015" border="0" alt="clip_image015" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnLk_qKN__I/AAAAAAAAA8A/gtJdPzmXFMo/clip_image015_thumb%5B1%5D.jpg?imgmax=800" width="440" height="343" /&gt;&lt;/a&gt;    &lt;br /&gt;&lt;b&gt;(2) &lt;/b&gt;Add Reference to the below DLLs for the BusinessLogicLayer and DataAccessLayer&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;System.Web&lt;/li&gt;    &lt;li&gt;System.Configuration&lt;/li&gt;    &lt;li&gt;CompanyName&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;(3) &lt;/b&gt;Add references of &amp;quot;CompanyName&amp;quot; and &amp;quot;BusinessLogicLayer&amp;quot; to the desktop application    &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnLlBsiAYKI/AAAAAAAAA8E/e5ctdEtk-To/s1600-h/clip_image017%5B6%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image017" border="0" alt="clip_image017" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnLlCUwSVxI/AAAAAAAAA8I/ZtdwpL_WnqE/clip_image017_thumb%5B3%5D.jpg?imgmax=800" width="279" height="463" /&gt;&lt;/a&gt;    &lt;br /&gt;&lt;b&gt;(4) &lt;/b&gt;Configuaring the App.config of the &amp;quot;PhoneBookApplication&amp;quot;    &lt;br /&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnLlDEh_XbI/AAAAAAAAA8M/VZGkASQUNuw/s1600-h/clip_image019%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image019" border="0" alt="clip_image019" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnLlFHllC7I/AAAAAAAAA8Q/9jZnDJnS3R4/clip_image019_thumb%5B1%5D.jpg?imgmax=800" width="571" height="402" /&gt;&lt;/a&gt; if you look to the xml elments in app.config, we define seciongroup named &amp;quot;PhoneBook&amp;quot; and added 2 sections to it which are &amp;quot;Person&amp;quot; and &amp;quot;Group&amp;quot;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnLlFjRluyI/AAAAAAAAA8U/i9pNSmWXL5k/s1600-h/clip_image020%5B17%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image020" border="0" alt="clip_image020" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnLlGf-h-tI/AAAAAAAAA8Y/wPOpADo6B3c/clip_image020_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;&amp;lt;sectionGroup name=&amp;quot;PhoneBook&amp;quot;&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;section name=&amp;quot;Person&amp;quot; type=&amp;quot;CompanyName.PhoneBook.DataAccessLayer.SectionConfig, DataAccessLayer&amp;quot; /&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;section name=&amp;quot;Group&amp;quot; type=&amp;quot;CompanyName.PhoneBook.DataAccessLayer.SectionConfig, DataAccessLayer&amp;quot; /&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/sectionGroup&amp;gt;&lt;/p&gt;  &lt;p&gt;then define that section group as:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnLlGxxq47I/AAAAAAAAA8c/gof3XjYu8sM/s1600-h/clip_image020%5B1%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image020[1]" border="0" alt="clip_image020[1]" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnLlHkdv_CI/AAAAAAAAA8g/HWkvpKb9_sg/clip_image020%5B1%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;&amp;lt;PhoneBook&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;Person&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;providers&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;add name=&amp;quot;SqlPerson&amp;quot; type=&amp;quot;CompanyName.PhoneBook.DataAccessLayer.SqlPersonProvider, DataAccessLayer&amp;quot;&lt;/p&gt;  &lt;p&gt;connectionStringName=&amp;quot;strcon&amp;quot; /&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;add name=&amp;quot;OraclePerson&amp;quot; type=&amp;quot;CompanyName.PhoneBook.DataAccessLayer.OraclePersonProvider, DataAccessLayer&amp;quot;&lt;/p&gt;  &lt;p&gt;connectionStringName=&amp;quot;OracleConnection&amp;quot; /&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;add name=&amp;quot;AccessPerson&amp;quot; type=&amp;quot;CompanyName.PhoneBook.DataAccessLayer.AccessPersonProvider, DataAccessLayer&amp;quot;&lt;/p&gt;  &lt;p&gt;connectionStringName=&amp;quot;AccessConnection&amp;quot; /&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/providers&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/Person&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;Group&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;providers&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;add name=&amp;quot;SqlGroup&amp;quot; type=&amp;quot;CompanyName.PhoneBook.DataAccessLayer.SqlGroupProvider, DataAccessLayer&amp;quot;&lt;/p&gt;  &lt;p&gt;connectionStringName=&amp;quot;strcon&amp;quot; /&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/providers&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/Group&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/PhoneBook&amp;gt;&lt;/p&gt;  &lt;p&gt;then define the connection strings for data stores of &amp;quot;SQL, Oracle and Access&amp;quot;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnLlH2r3n5I/AAAAAAAAA8k/oHCU3WxI2uc/s1600-h/clip_image020%5B2%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image020[2]" border="0" alt="clip_image020[2]" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnLlI5hsDVI/AAAAAAAAA8o/qU5rnCt02No/clip_image020%5B2%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;&amp;lt;connectionStrings&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;add name=&amp;quot;strcon&amp;quot; connectionString=&amp;quot;Data Source=.;Initial Catalog=AhmedEid_PhoneBook;Integrated Security=True&amp;quot; /&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;add name=&amp;quot;OracleConnection&amp;quot; connectionString=&amp;quot;oracle_connection_string&amp;quot; /&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;add name=&amp;quot;AccessConnection&amp;quot; connectionString=&amp;quot;Access_connection_string&amp;quot; /&amp;gt;&lt;/p&gt;  &lt;p&gt;&amp;lt;/connectionStrings&amp;gt;&lt;/p&gt;  &lt;p&gt;person provider could retrieve data from SQL,Oracle or Access database.   &lt;br /&gt;Group provider could retrieve data from SQL only &lt;b&gt;(5) &lt;/b&gt;Implementing DataAccessLayer Suppose PhoneBook is a midsize business and the PhoneBookApplicaion contains 2 major sections: - Person : profile management    &lt;br /&gt;- Groups : categorization of persons The following code reads all providers defined in your web.config. That is all you have to do to make providers information available to other classes.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnLlJoCXmII/AAAAAAAAA8s/LgbDMODU84Q/s1600-h/clip_image020%5B3%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image020[3]" border="0" alt="clip_image020[3]" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnLlKLms0JI/AAAAAAAAA8w/EdnQZGgWMZs/clip_image020%5B3%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;using System;&lt;/p&gt;  &lt;p&gt;using System.Configuration;&lt;/p&gt;  &lt;p&gt;namespace CompanyName.PhoneBook.DataAccessLayer&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;public class SectionConfig : ConfigurationSection&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;[ConfigurationProperty(&amp;quot;providers&amp;quot;)]&lt;/p&gt;  &lt;p&gt;public ProviderSettingsCollection Providers&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;return (ProviderSettingsCollection)base[&amp;quot;providers&amp;quot;];&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;We need to create another class to have access to the Framework provider collection and to add our new provider(s) to the provider collection.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnLlLb2_0FI/AAAAAAAAA80/5V-vBt8siOw/s1600-h/clip_image020%5B4%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image020[4]" border="0" alt="clip_image020[4]" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnLlMFGJ70I/AAAAAAAAA84/3ikXgniZpEQ/clip_image020%5B4%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;using System;&lt;/p&gt;  &lt;p&gt;using System.Configuration.Provider;&lt;/p&gt;  &lt;p&gt;namespace CompanyName.PhoneBook.DataAccessLayer&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;public class ProviderList : ProviderCollection&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;public override void Add(ProviderBase provider)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;if (provider == null) throw new ArgumentNullException(&amp;quot;The provider parameter cannot be null.&amp;quot;);&lt;/p&gt;  &lt;p&gt;base.Add(provider);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;Create another class that will initialize the provider by the provider name.   &lt;br /&gt;example: initialize the &lt;b&gt;Group provider &lt;/b&gt;for SQLGroupProvider class using provider name of &amp;quot;SQLGroup&amp;quot;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnLlMoPadJI/AAAAAAAAA88/AZ0vtA1ZhzE/s1600-h/clip_image020%5B5%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image020[5]" border="0" alt="clip_image020[5]" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnLlNWM6mkI/AAAAAAAAA9A/iWsdw72zfJg/clip_image020%5B5%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;using System;&lt;/p&gt;  &lt;p&gt;using System.Collections.Generic;&lt;/p&gt;  &lt;p&gt;using System.Text;&lt;/p&gt;  &lt;p&gt;using System.Web.Configuration;&lt;/p&gt;  &lt;p&gt;using System.Configuration;&lt;/p&gt;  &lt;p&gt;using CompanyName.PhoneBook.DataAccessLayer;&lt;/p&gt;  &lt;p&gt;namespace CompanyName.PhoneBook.DataAccessLayer&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;public abstract class InitMember&amp;lt;T&amp;gt;&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;public static ProviderList Providers(string _providerSectionName)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;SectionConfig qc = (SectionConfig)ConfigurationManager.GetSection(_providerSectionName);&lt;/p&gt;  &lt;p&gt;providerCollection = new ProviderList();&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// this wl instatiate PersonProvider with the class &amp;quot;personimpl&amp;quot; which inherit it&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;ProvidersHelper.InstantiateProviders(qc.Providers, providerCollection, typeof(T));&lt;/p&gt;  &lt;p&gt;providerCollection.SetReadOnly();&lt;/p&gt;  &lt;p&gt;return providerCollection;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;private static ProviderList providerCollection;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;The class takes the provider you want to initialize, i.e PersonProvider, its class and the provider name   &lt;br /&gt;This enum founded on CompanyName.Globals class    &lt;br /&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnLlOEmFouI/AAAAAAAAA9E/Ub8iRNitf4Y/s1600-h/clip_image022%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image022" border="0" alt="clip_image022" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnLlO5nlf2I/AAAAAAAAA9I/rUHjkn9Ssx4/clip_image022_thumb%5B1%5D.jpg?imgmax=800" width="442" height="263" /&gt;&lt;/a&gt;    &lt;br /&gt;using that class from the Instance method of PersonProvider Class:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnLlP9v3YII/AAAAAAAAA9M/sbsLG_SvKdc/s1600-h/clip_image020%5B6%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image020[6]" border="0" alt="clip_image020[6]" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnLlQd_19xI/AAAAAAAAA9Q/oikBA_WPeDk/clip_image020%5B6%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; This will initialize the provider and add instanse to the providers list&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;param&lt;/i&gt;&lt;i&gt; &lt;/i&gt;&lt;i&gt;name=&amp;quot;_Provider&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public static PersonProvider Instance(Globals.Providers _Provider)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;return (DataAccessLayer.PersonProvider)DataAccessLayer.InitMember&lt;/p&gt;  &lt;p&gt;&amp;lt;DataAccessLayer.PersonProvider&amp;gt;.Providers(&amp;quot;PhoneBook/Person&amp;quot;)[_Provider.ToString()];&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;This method will initialize the provider and add instance to the providers list   &lt;br /&gt;Now our &amp;quot;DataAccessLayer&amp;quot; project has the necessary classes for all providers to be later developed.    &lt;br /&gt;so we are going to develop two providers:    &lt;br /&gt;- PersonProvider    &lt;br /&gt;- GroupProvider&lt;/p&gt;  &lt;p&gt;· Now, we create our provider model:   &lt;br /&gt;BaseProvider --&amp;gt; xxxProvider --&amp;gt; SQLxxxProvider xxx is the name of entity like Person, Group, ....etc Person Provider Classes:    &lt;br /&gt;    &lt;br /&gt;Group Provider Classes:    &lt;br /&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnLlQ_a4LgI/AAAAAAAAA9U/nOvjxH5TwTg/s1600-h/clip_image026%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image026" border="0" alt="clip_image026" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnLlSPUGC1I/AAAAAAAAA9Y/Wf2wBMGzxMk/clip_image026_thumb%5B1%5D.jpg?imgmax=800" width="406" height="446" /&gt;&lt;/a&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnLlTOU93ZI/AAAAAAAAA9c/1J17SGVf-TI/s1600-h/clip_image024%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image024" border="0" alt="clip_image024" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnLlUnRDlmI/AAAAAAAAA9g/uevkkDiyaWA/clip_image024_thumb%5B1%5D.jpg?imgmax=800" width="493" height="461" /&gt;&lt;/a&gt;    &lt;br /&gt;Let me explain the implementation of the PersonProvider and you can create GroupProvider by yourself: first we create a class named &lt;b&gt;&amp;quot;PersonProvider.cs&amp;quot;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnLlVtkpVqI/AAAAAAAAA9k/ChUQqndKcG8/s1600-h/clip_image020%5B7%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image020[7]" border="0" alt="clip_image020[7]" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnLlXGK9yLI/AAAAAAAAA9o/m9ObBxH6Omk/clip_image020%5B7%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;using System;&lt;/p&gt;  &lt;p&gt;using CompanyName.PhoneBook.Providers;&lt;/p&gt;  &lt;p&gt;using System.Configuration.Provider;&lt;/p&gt;  &lt;p&gt;using System.Configuration;&lt;/p&gt;  &lt;p&gt;using System.Web.Configuration;&lt;/p&gt;  &lt;p&gt;namespace CompanyName.PhoneBook.DataAccessLayer&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;public abstract class PersonProvider : ProviderBase&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; This will initialize the provider and add instanse to the providers list&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;param&lt;/i&gt;&lt;i&gt; &lt;/i&gt;&lt;i&gt;name=&amp;quot;_Provider&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public static PersonProvider Instance(Globals.Providers _Provider)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;return (DataAccessLayer.PersonProvider)DataAccessLayer.InitMember&lt;/p&gt;  &lt;p&gt;&amp;lt;DataAccessLayer.PersonProvider&amp;gt;.Providers(&amp;quot;PhoneBook/Person&amp;quot;)[_Provider.ToString()];&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Add new person&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;param&lt;/i&gt;&lt;i&gt; &lt;/i&gt;&lt;i&gt;name=&amp;quot;_info&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public abstract bool Add(PersonInfo _info);&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Modify selected person&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;param&lt;/i&gt;&lt;i&gt; &lt;/i&gt;&lt;i&gt;name=&amp;quot;_info&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public abstract bool Modify(PersonInfo _info);&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Delete selected person&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;param&lt;/i&gt;&lt;i&gt; &lt;/i&gt;&lt;i&gt;name=&amp;quot;_PersonId&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public abstract bool Delete(int _PersonId);&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Get all personns&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public abstract PersonInfo[] Find();&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Get info of person&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;param&lt;/i&gt;&lt;i&gt; &lt;/i&gt;&lt;i&gt;name=&amp;quot;_PersonId&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public abstract PersonInfo GetInfo(int _PersonId);&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Get personns that match a given criteria&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;param&lt;/i&gt;&lt;i&gt; &lt;/i&gt;&lt;i&gt;name=&amp;quot;_Searchinfo&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public abstract PersonInfo[] Find(SearchCriteriaInfo _Searchinfo);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;Instance() method : is responsible for instantiating our concrete (implementer) class (SqlGeneralProvider.cs), which has been defined within Web.config. and &amp;quot;PersonProvider&amp;quot; abstract class, which it inherits from ProviderBase and include person abstracted functions. (6)   &lt;br /&gt;BusinessLogicLayer    &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnLlX153w5I/AAAAAAAAA9s/VwR_eC0Zktg/s1600-h/clip_image028%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image028" border="0" alt="clip_image028" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnLlYy5bLNI/AAAAAAAAA9w/7w2LwkDzWW4/clip_image028_thumb%5B1%5D.jpg?imgmax=800" width="390" height="324" /&gt;&lt;/a&gt;    &lt;br /&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;&lt;b&gt;Note:&lt;/b&gt; It is a good idea to add a Helper class into your BusinessLogicLayer project. This way, you can expose some common functionality to all of your BusinessLogicLayer classes just by inheriting from this helper class.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnLlZQHdTtI/AAAAAAAAA90/iQu7lVeqyHE/s1600-h/clip_image020%5B8%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image020[8]" border="0" alt="clip_image020[8]" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnLlZ7K88CI/AAAAAAAAA94/cn4CzvYGVQc/clip_image020%5B8%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;using System;&lt;/p&gt;  &lt;p&gt;using System.Collections.Generic;&lt;/p&gt;  &lt;p&gt;using System.Text;&lt;/p&gt;  &lt;p&gt;using System.Web;&lt;/p&gt;  &lt;p&gt;namespace CompanyName.PhoneBook.BusinessLogicLayer&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; You can use helper to provide common info./data needed OR to massage or add more info. &lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; to your data before sending it to presentation.&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public abstract class Helper&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;protected static string MachineName&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;get&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;return Environment.MachineName;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Add more methods/properties below&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;then define the business classes for the Person and Group providers.   &lt;br /&gt;&lt;b&gt;Person.cs&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnLlaeZGJtI/AAAAAAAAA98/KqkwtJy_zAM/s1600-h/clip_image020%5B9%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image020[9]" border="0" alt="clip_image020[9]" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnLlaydi1EI/AAAAAAAAA-A/1Kp8G0gGSAI/clip_image020%5B9%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;using System;&lt;/p&gt;  &lt;p&gt;using System.Collections.Generic;&lt;/p&gt;  &lt;p&gt;using System.Text;&lt;/p&gt;  &lt;p&gt;using CompanyName.PhoneBook.Providers;&lt;/p&gt;  &lt;p&gt;using CompanyName.PhoneBook.DataAccessLayer;&lt;/p&gt;  &lt;p&gt;namespace CompanyName.PhoneBook.BusinessLogicLayer&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;public abstract class Person : Helper&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;static PersonProvider objPersonProvider;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Person Cnstructor&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;//Class Constructor: will be invoked 1 time only / Appdomain&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;static Person()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;objPersonProvider = PersonProvider.Instance(Globals.Providers.SqlPerson);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// staticed methods for person&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Add new person&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;param&lt;/i&gt;&lt;i&gt; &lt;/i&gt;&lt;i&gt;name=&amp;quot;_info&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public static bool Add(PersonInfo _info)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// You can use helper to provide common info./data needed OR to&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// massage or add more info. to your data before sending it to&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// presentation.&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Here we use helper class to get MachineName and pass it along&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// with data to presentation.&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;return objPersonProvider.Add(_info);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Modify selected person&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;param&lt;/i&gt;&lt;i&gt; &lt;/i&gt;&lt;i&gt;name=&amp;quot;_info&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public static bool Modify(PersonInfo _info) &lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;return objPersonProvider.Modify(_info);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Delete selected person&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;param&lt;/i&gt;&lt;i&gt; &lt;/i&gt;&lt;i&gt;name=&amp;quot;_PersonId&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public static bool Delete(int _PersonId) { return objPersonProvider.Delete(_PersonId); }&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Get all personns&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public static PersonInfo[] Find() { return objPersonProvider.Find(); }&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Get info of person&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;param&lt;/i&gt;&lt;i&gt; &lt;/i&gt;&lt;i&gt;name=&amp;quot;_PersonId&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public static PersonInfo GetInfo(int _PersonId) { return objPersonProvider.GetInfo(_PersonId); }&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; Get personns that match a given criteria&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;/summary&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;param&lt;/i&gt;&lt;i&gt; &lt;/i&gt;&lt;i&gt;name=&amp;quot;_Searchinfo&amp;quot;&amp;gt;&amp;lt;/param&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;///&lt;i&gt; &lt;/i&gt;&lt;i&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;public static PersonInfo[] Find(SearchCriteriaInfo _Searchinfo) { return objPersonProvider.Find(_Searchinfo); }&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;define &lt;b&gt;objPersonProvider&lt;/b&gt; as PersonProvider to be shared among the instances of Person class. Then initialize it on the class constructor which will be invoked for one time/ Appdomain&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnLlbSdwx7I/AAAAAAAAA-E/cYVmJY3Yguk/s1600-h/clip_image020%5B10%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image020[10]" border="0" alt="clip_image020[10]" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnLlcH_rvLI/AAAAAAAAA-I/nXPDMLZU7ZI/clip_image020%5B10%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;Person objPerson_1 = new Person(); &lt;i&gt;// on class A&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;Person objPerson_2 = new Person(); &lt;i&gt;// on class B &lt;/i&gt;&lt;/p&gt;  &lt;p&gt;Person objPerson_3 = new Person(); &lt;i&gt;// on class C &lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;//Class Constructor: will be invoked 1 time only / Appdomain&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;static Person()&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;objPersonProvider = PersonProvider.Instance(Globals.Providers.SqlPerson);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;The objPersonProvider will be initialized with the objPerson_1 constructor only on the class A, then other instances like objPerson_2 or objPerson_3 will use the static object objPersonProvider. you can add you business logic to every method before calling the data access provider as&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnLld1W9bUI/AAAAAAAAA-M/xUP6ghVZ-J8/s1600-h/clip_image020%5B11%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image020[11]" border="0" alt="clip_image020[11]" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnLlfcAQS8I/AAAAAAAAA-Q/Dn07AwO8vBs/clip_image020%5B11%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;public static bool Add(PersonInfo _info)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// Here: you can add you business logic to every method before calling the data access provider&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;return objPersonProvider.Add(_info);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&lt;b&gt;PhoneBook Application&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The presentation layer as desktop application for implementing the business logic to the client. &amp;lt;image31&amp;gt;   &lt;br /&gt;&lt;b&gt;How to use the BL layer from the presentation layer ? sample code&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnLlgIPRQEI/AAAAAAAAA-U/m9tNxKcnBqs/s1600-h/clip_image020%5B12%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image020[12]" border="0" alt="clip_image020[12]" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnLlgsXjryI/AAAAAAAAA-Y/Sowhknmd9sw/clip_image020%5B12%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// build the search criteria&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;SearchCriteriaInfo objSearchInfo = new SearchCriteriaInfo();&lt;/p&gt;  &lt;p&gt;objSearchInfo.FilterNameBy = (Globals.FilterNameBy)this.cboName.SelectedValue;&lt;/p&gt;  &lt;p&gt;objSearchInfo.GroupId = (int)cboGroup.SelectedValue;&lt;/p&gt;  &lt;p&gt;objSearchInfo.Name = txtName.Text.Trim();&lt;/p&gt;  &lt;p&gt;if(chkFrom.Checked)&lt;/p&gt;  &lt;p&gt;objSearchInfo.FromDate = datefrom.Value;&lt;/p&gt;  &lt;p&gt;if(chkTo.Checked)&lt;/p&gt;  &lt;p&gt;objSearchInfo.ToDate = dateto.Value;&lt;/p&gt;  &lt;p&gt;objSearchInfo.SortBy = (rdoasc.Checked) ? Globals.SortBy.Asc : Globals.SortBy.Desc;&lt;/p&gt;  &lt;p&gt;objSearchInfo.SortByBirthDate = chkbirthdate.Checked; ;&lt;/p&gt;  &lt;p&gt;objSearchInfo.SortByGroup = chkGroup.Checked;&lt;/p&gt;  &lt;p&gt;objSearchInfo.SortByName = chkName.Checked;&lt;/p&gt;  &lt;p&gt;objSearchInfo.SortByTele = chkTele.Checked;&lt;/p&gt;  &lt;p&gt;objSearchInfo.TeleNumber = txtTeleNumber.Text.Trim();&lt;/p&gt;  &lt;p&gt;objSearchInfo.TelephoneType = (Globals.TelephoneTypes)this.cboTeleTypes.SelectedValue;&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// get result from bus logic layer&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;PersonInfo[] objresult = Person.Find(objSearchInfo);&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnLlhWz16FI/AAAAAAAAA-c/Oh9CIZvVXN4/s1600-h/clip_image030%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image030" border="0" alt="clip_image030" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnLlikDlnKI/AAAAAAAAA-g/q6ae-ZDpK_0/clip_image030_thumb%5B1%5D.jpg?imgmax=800" width="567" height="441" /&gt;&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnLljbcA8TI/AAAAAAAAA-k/Lh0HjtVb2pA/s1600-h/clip_image032%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image032" border="0" alt="clip_image032" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnLlkY6B0qI/AAAAAAAAA-o/Lw5w4AicpdY/clip_image032_thumb%5B1%5D.jpg?imgmax=800" width="517" height="492" /&gt;&lt;/a&gt;    &lt;br /&gt;&lt;b&gt;How to save and retrieve image from database ?&lt;/b&gt;Save to database:    &lt;br /&gt;save the image from the picturebox to MemoryStream and then save it on database as Byte[]&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnLlk4gecrI/AAAAAAAAA-s/AsFCxPhOMIM/s1600-h/clip_image020%5B13%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image020[13]" border="0" alt="clip_image020[13]" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnLllbHTWjI/AAAAAAAAA-w/AKbjLadwSio/clip_image020%5B13%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// prapare the image&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;if (null != imgperson.Image) &lt;i&gt;// picturebox control &lt;/i&gt;&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;MemoryStream stream = new MemoryStream();&lt;/p&gt;  &lt;p&gt;imgperson.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);&lt;/p&gt;  &lt;p&gt;info.Image = stream.ToArray();&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;Retrieve from database:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnLlmHYgnTI/AAAAAAAAA-0/xb8liwvwO_Y/s1600-h/clip_image020%5B14%5D%5B2%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image020[14]" border="0" alt="clip_image020[14]" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnLlnVoljTI/AAAAAAAAA-4/3AG3OMVljl4/clip_image020%5B14%5D_thumb.gif?imgmax=800" width="9" height="9" /&gt;&lt;/a&gt; Collapse&lt;/p&gt;  &lt;p&gt;&lt;i&gt;// display the image&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;byte[] PImage = info.Image;&lt;/p&gt;  &lt;p&gt;if (null != PImage)&lt;/p&gt;  &lt;p&gt;{&lt;/p&gt;  &lt;p&gt;MemoryStream stream = new MemoryStream(PImage);&lt;/p&gt;  &lt;p&gt;imgperson.Image = Image.FromStream(stream);&lt;/p&gt;  &lt;p&gt;}&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnLlo2zCSyI/AAAAAAAAA-8/UabzQMc-W1E/s1600-h/clip_image034%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image034" border="0" alt="clip_image034" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnLlqovYjuI/AAAAAAAAA_A/yPjypB_hdsQ/clip_image034_thumb%5B1%5D.jpg?imgmax=800" width="495" height="389" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Restoring Database on SQL Server 2005&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Attach the database AhmedEid_PhoneBook.mdf from the directory DataBase on the root directory to the SQL Server Engine.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Debugging Scenario&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Let us debug the advanced search button code to retrieve results with criteria from the client   &lt;br /&gt;the following scenario will lead you to understand the Provider implementation&lt;/p&gt;  &lt;p&gt;make breakpoints as the following   &lt;br /&gt;1- AdvancedSearch form class ( presentation layer )    &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnLlrfwJvPI/AAAAAAAAA_E/7k7UjurnoT0/s1600-h/clip_image036%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image036" border="0" alt="clip_image036" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnLlsYLFP_I/AAAAAAAAA_I/Y0tHbIOxUss/clip_image036_thumb%5B1%5D.jpg?imgmax=800" width="554" height="433" /&gt;&lt;/a&gt;    &lt;br /&gt;2- Person class of BusinessLogicLayer ( BLL layer )    &lt;br /&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnLls0gc-uI/AAAAAAAAA_M/yDsUgars5TA/s1600-h/clip_image038%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image038" border="0" alt="clip_image038" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnLltyYETeI/AAAAAAAAA_Q/883bZv9cQ3s/clip_image038_thumb%5B1%5D.jpg?imgmax=800" width="552" height="344" /&gt;&lt;/a&gt;    &lt;br /&gt;3- PersonProvider Class of DataAccessLayer ( DAL layer )    &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnLluSj92eI/AAAAAAAAA_U/3h6f_hzJ3HA/s1600-h/clip_image040%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image040" border="0" alt="clip_image040" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnLlvBWewSI/AAAAAAAAA_Y/8Jj-F6sVc6w/clip_image040_thumb%5B1%5D.jpg?imgmax=800" width="590" height="288" /&gt;&lt;/a&gt;    &lt;br /&gt;4- InittMember&amp;lt;T&amp;gt; class of DataAccessLayer ( DAL layer )    &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnLlv6i36OI/AAAAAAAAA_c/PJYXExNr4Nc/s1600-h/clip_image042%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image042" border="0" alt="clip_image042" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnLlxI253wI/AAAAAAAAA_g/0RbMYy_ijwQ/clip_image042_thumb%5B1%5D.jpg?imgmax=800" width="580" height="198" /&gt;&lt;/a&gt;    &lt;br /&gt;the above code will provide and add the SqlPersonProvider class to the providers list to be available for any usage.    &lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnLlx2PFzcI/AAAAAAAAA_k/egRN9PxfoFM/s1600-h/clip_image044%5B5%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image044" border="0" alt="clip_image044" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnLlzKAVw9I/AAAAAAAAA_o/dgnraVrKkDU/clip_image044_thumb%5B2%5D.jpg?imgmax=800" width="621" height="169" /&gt;&lt;/a&gt;    &lt;br /&gt;5- SqlGroupProvider class of DataAccesslayer ( DAL layer )    &lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnLl0vKKCTI/AAAAAAAAA_s/BmmVbArof6M/s1600-h/clip_image046%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image046" border="0" alt="clip_image046" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnLl1i6fO8I/AAAAAAAAA_w/jnNt0gi7oRI/clip_image046_thumb%5B1%5D.jpg?imgmax=800" width="598" height="332" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Note: After debugging the code for 1st time , the providers (PersonProvider and groupProvider) will be added to the System.Configuration.Provider.ProviderCollection and for 2nd time the results will be retrieved without instantiating the classes again.   &lt;br /&gt;&lt;b&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnLl2Xn6PlI/AAAAAAAAA_0/HzYcnnUJaaw/s1600-h/clip_image048%5B4%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image048" border="0" alt="clip_image048" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnLl2w7gW5I/AAAAAAAAA_4/DOTVzTS-j80/clip_image048_thumb%5B1%5D.jpg?imgmax=800" width="586" height="196" /&gt;&lt;/a&gt;&lt;/b&gt;&lt;b&gt; &lt;/b&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;&lt;b&gt;References &lt;/b&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;&lt;b&gt;- &lt;a href="http://msdn.microsoft.com/en-us/library/ms972319.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms972319.aspx&lt;/a&gt; &lt;/b&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;&lt;b&gt;- &lt;a href="http://msdn.microsoft.com/en-us/library/ms972370.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms972370.aspx&lt;/a&gt; &lt;/b&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;&lt;b&gt;- &lt;a href="http://msdn.microsoft.com/en-us/library/ms978496.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms978496.aspx&lt;/a&gt; &lt;/b&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;&lt;b&gt;- &lt;a href="http://en.wikipedia.org/wiki/Design_Patterns"&gt;http://en.wikipedia.org/wiki/Design_Patterns&lt;/a&gt; &lt;/b&gt;&lt;b&gt;     &lt;br /&gt;&lt;/b&gt;&lt;b&gt;- &lt;a href="http://www.c-sharpcorner.com/UploadFile/webmaster3/ProviderPattern12242007184126PM/ProviderPattern.aspx"&gt;http://www.c-sharpcorner.com/UploadFile/webmaster3/ProviderPattern12242007184126PM/ProviderPattern.aspx&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Top of Form&lt;/p&gt;  &lt;p&gt;&lt;b&gt;License&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;This article, along with any associated source code and files, is licensed under &lt;a href="http://www.codeproject.com/info/cpol10.aspx"&gt;The Code Project Open License (CPOL)&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;About the Author&lt;/b&gt;    &lt;table border="0" cellspacing="5" cellpadding="0"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="140"&gt;           &lt;p&gt;&lt;b&gt;&lt;a href="http://www.codeproject.com/Members/Ahmad-Eid-Salim"&gt;Ahmad Eid Salim&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;            &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnLl3tjfWqI/AAAAAAAAA_8/DQ2gtidH0RI/s1600-h/clip_image049%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image049" border="0" alt="clip_image049" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnLl417g5FI/AAAAAAAABAA/Pw5kbJlOkVw/clip_image049_thumb.jpg?imgmax=800" width="154" height="154" /&gt;&lt;/a&gt;&lt;/p&gt;            &lt;p&gt;Member&lt;/p&gt;         &lt;/td&gt;          &lt;td valign="top"&gt;&amp;#160;&lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/p&gt;  &lt;p&gt;Bottom of Form&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-2555675350898847549?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/2555675350898847549/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2009/07/provider-design-patterns-in-net-20.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/2555675350898847549'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/2555675350898847549'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2009/07/provider-design-patterns-in-net-20.html' title='Provider Design Patterns in NET 2.0'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_iuwZHhydmEs/SnLkvPSF6bI/AAAAAAAAA7M/dPJACdIBmYY/s72-c/clip_image002_thumb%5B1%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-7753217174161685835</id><published>2009-07-31T05:29:00.001-07:00</published><updated>2009-07-31T05:29:30.020-07:00</updated><title type='text'>SQL Server 2005 - Merge Replication Step by Step Procedure</title><content type='html'>&lt;p&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Replication&lt;/b&gt; is a set of technologies for copying and distributing data and database objects from one database to another and then synchronizing between databases to maintain consistency. Using replication, you can distribute data to different locations and to remote or mobile users over local and wide area networks, dial-up connections, wireless connections, and the Internet.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Replication&lt;/b&gt; is the process of sharing data between databases in different locations. Using replication, we can create copies of the database and share the copy with different users so that they can make changes to their local copy of database and later synchronize the changes to the source database.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Terminologies before getting started:&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Microsoft SQL Server 2000 supports the following types of replication&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Publisher&lt;/b&gt; is a server that makes the data available for subscription to other servers. In addition to that, publisher also identifies what data has changed at the subscriber during the synchronizing process. Publisher contains &lt;b&gt;publication(s)&lt;/b&gt;.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Subscriber&lt;/b&gt; is a server that receives and maintains the published data. Modifications to the data at subscriber can be propagated back to the publisher.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Distributor&lt;/b&gt; is the server that manages the flow of data through the replication system. Two types of distributors are present, one is remote distributor and the other one local distributor. Remote distributor is separate from publisher and is configured as distributor for replication. Local distributor is a server that is configured as publisher and distributor.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Agents&lt;/b&gt; are the processes that are responsible for copying and distributing data between publisher and subscriber. There are different types of agents supporting different types of replication.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Snapshot Agent&lt;/b&gt; is an executable file that prepares snapshot files containing schema and data of published tables and database objects, stores the files in the snapshot folder, and records synchronization jobs in the distribution database.&lt;/p&gt;  &lt;p&gt;An &lt;b&gt;article&lt;/b&gt; can be any database object, like Tables (Column filtered or Row filtered), Views, Indexed views, Stored Procedures, and User defined functions.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Publication&lt;/b&gt; is a collection of articles.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Subscription&lt;/b&gt; is a request for copy of data or database objects to be replicated.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnLjOWzO86I/AAAAAAAAA5I/0ESIklZIQRE/s1600-h/clip_image002%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnLjPadL5sI/AAAAAAAAA5M/dkz9OcWlhyI/clip_image002_thumb.jpg?imgmax=800" width="346" height="324" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Replication Types&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Microsoft SQL Server 2005 supports the following types of replication:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Snapshot Replication&lt;/li&gt;    &lt;li&gt;Transactional Replication&lt;/li&gt;    &lt;li&gt;Merge Replication&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;Snapshot Replication&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Snapshot replication is also known as static replication. Snapshot replication copies and distributes data and database objects exactly as they appear at the current moment in time.&lt;/li&gt;    &lt;li&gt;Subscribers are updated with complete modified data and not by individual transactions, and are not continuous in nature.&lt;/li&gt;    &lt;li&gt;This type is mostly used when the amount of data to be replicated is small and data/DB objects are static or does not change frequently.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;Transactional Replication&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Transactional replication is also known as dynamic replication. In transactional replication, modifications to the publication at the publisher are propagated to the subscriber incrementally.&lt;/li&gt;    &lt;li&gt;Publisher and the subscriber are always in synchronization and should always be connected.&lt;/li&gt;    &lt;li&gt;This type is mostly used when subscribers always need the latest data for processing.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;Merge replication&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;It allows making autonomous changes to replicated data on the Publisher and on the Subscriber. With merge replication, SQL Server captures all incremental data changes in the source and in the target databases, and reconciles conflicts according to rules you configure or using a custom resolver you create. Merge replication is best used when you want to support autonomous changes on the replicated data on the Publisher and on the Subscriber.&lt;/p&gt;  &lt;p&gt;Replication agents involved in merge replication are snapshot agent and merge agent.&lt;/p&gt;  &lt;p&gt;Implement merge replication if, changes are made constantly at the publisher and subscribing servers, and must be merged in the end.&lt;/p&gt;  &lt;p&gt;By default, the publisher wins all conflicts that it has with subscribers because it has the highest priority. Conflict resolver can be customized&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Before starting the replication process:&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;assume that we have 2 server:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;b&gt;EGYPT-AEID&lt;/b&gt;: is the publisher server ( contains HRatPublisher )&lt;/li&gt;    &lt;li&gt;&lt;b&gt;SPS&lt;/b&gt;:&lt;b&gt; &lt;/b&gt;is the subscriber server ( contains HRatSubscriber ) &lt;i&gt;use SQL server Authentication mode for login&lt;/i&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;on the publisher database i created table: Employees with fields of (ID, Name, Salary) to replicate its data to the subscriber server.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;i will use publisher as subscriber also&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Note: Check that SQL Server Agent is running on the publisher and the subscriber&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Steps:&lt;/b&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Open SQL Server&lt;b&gt; &lt;/b&gt;Management Studio and login with &lt;i&gt;SQL Server Authentication&lt;/i&gt; to configure Publishing, Subscribers, and Distribution&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnLjQ7lGEPI/AAAAAAAAA5Q/p_bX64SvSdQ/s1600-h/clip_image004%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnLjR4uUMwI/AAAAAAAAA5U/fiAHeNjbcUQ/clip_image004_thumb.jpg?imgmax=800" width="303" height="324" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;a- Configure the appropriate server as publisher or distributor.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnLjSj43mOI/AAAAAAAAA5Y/yW3Pgr9eoOg/s1600-h/clip_image006%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnLjTUQTwYI/AAAAAAAAA5c/-_JnBWJEigk/clip_image006_thumb.jpg?imgmax=800" width="423" height="298" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;b- Enable the appropriate database for merge replication&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnLjUs-wx2I/AAAAAAAAA5g/yzMtDyjqtFk/s1600-h/clip_image008%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnLjVdCLNfI/AAAAAAAAA5k/sAMEZ7MU1y0/clip_image008_thumb.jpg?imgmax=800" width="390" height="324" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;2- Create new local publication from DB-Server --&amp;gt; Replication --&amp;gt; Local Publications --&amp;gt; Right Click --&amp;gt; New Pub&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnLjWHRFvMI/AAAAAAAAA5o/IXupiEOFR8k/s1600-h/clip_image009%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image009" border="0" alt="clip_image009" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnLjW730LlI/AAAAAAAAA5s/QI3vpCEpNIA/clip_image009_thumb.jpg?imgmax=800" width="423" height="231" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;then choose the database that contains the data or objects you want to replicate&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnLjX3G0TdI/AAAAAAAAA5w/QOtk-iUQzz4/s1600-h/clip_image011%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image011" border="0" alt="clip_image011" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnLjY5VVSSI/AAAAAAAAA50/UQH95bKqLJI/clip_image011_thumb.jpg?imgmax=800" width="383" height="324" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;then choose the replication type and then specify the SQL server versions that will be used by subscribers to that publication like SQL Server 2005, SQL mobile Edition, SQL for Win CE ....etc&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnLjZ8Z1e_I/AAAAAAAAA54/b4iclAfcC58/s1600-h/clip_image013%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image013" border="0" alt="clip_image013" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnLjakGEuhI/AAAAAAAAA58/EKteKfeeYC0/clip_image013_thumb.jpg?imgmax=800" width="423" height="291" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;after that manage the replication articles, data and db objects, by choosing objects to be replicated&lt;/p&gt;  &lt;p&gt;Note: you can manage the replication properties for selected objects&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnLjb-89-hI/AAAAAAAAA6A/FUsH283KqGc/s1600-h/clip_image014%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image014" border="0" alt="clip_image014" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnLjccbx87I/AAAAAAAAA6E/nLISz9Ybx4k/clip_image014_thumb.jpg?imgmax=800" width="423" height="213" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Then add filters to published tables to optimize performance and then configure the &lt;b&gt;snapshot agent&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnLjdCvmyEI/AAAAAAAAA6I/hKWfiGakKRc/s1600-h/clip_image015%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image015" border="0" alt="clip_image015" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnLjd062GFI/AAAAAAAAA6M/BBAmhahYoFc/clip_image015_thumb.jpg?imgmax=800" width="359" height="324" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnLje4yJiqI/AAAAAAAAA6Q/kpoWkgHjcF0/s1600-h/clip_image017%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image017" border="0" alt="clip_image017" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnLjgf8cgZI/AAAAAAAAA6U/etU7ME6eyH0/clip_image017_thumb.jpg?imgmax=800" width="368" height="324" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;and configure the security for snapshot agent&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnLjhJjlGPI/AAAAAAAAA6Y/b1S7xtRyu4Q/s1600-h/clip_image019%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image019" border="0" alt="clip_image019" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnLjhn3HigI/AAAAAAAAA6c/hYwDg8vS1CQ/clip_image019_thumb.jpg?imgmax=800" width="423" height="217" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;finally rename the publication and click finish&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnLjimdb0FI/AAAAAAAAA6g/l2YBGq79UJ0/s1600-h/clip_image021%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image021" border="0" alt="clip_image021" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnLjjBu9hvI/AAAAAAAAA6k/UQ0DR2Tzb9g/clip_image021_thumb.jpg?imgmax=800" width="354" height="324" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;3- create a new subscription for the created &amp;quot;&lt;b&gt;MyPublication01&lt;/b&gt;&amp;quot; Publication by right click on MyPublication01 --&amp;gt; New Subscription&lt;/p&gt;  &lt;p&gt;that to configure the &amp;quot;Merge Agent&amp;quot; for replication on the subscriber database&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnLjj1wA6iI/AAAAAAAAA6o/hoJYrnSOGss/s1600-h/clip_image022%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image022" border="0" alt="clip_image022" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnLjlFBm6wI/AAAAAAAAA6s/Sh0raO6dhdM/clip_image022_thumb.jpg?imgmax=800" width="423" height="215" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnLjlnfFkMI/AAAAAAAAA6w/54FKWllLU3w/s1600-h/clip_image023%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image023" border="0" alt="clip_image023" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnLjm-o5XXI/AAAAAAAAA60/qWuORRDXt1Q/clip_image023_thumb.jpg?imgmax=800" width="423" height="221" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;then choose one or more subscriber databases. you can add new &lt;b&gt;SQL Server subscribers&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnLjn_cjHfI/AAAAAAAAA64/kFeMCuyYsM8/s1600-h/clip_image025%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image025" border="0" alt="clip_image025" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnLjorpvYJI/AAAAAAAAA68/NYOOlsDwuDw/clip_image025_thumb.jpg?imgmax=800" width="381" height="324" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;then specify the Merge Agent security as mentioned above on &amp;quot;Agent Snapshot&amp;quot;&lt;/p&gt;  &lt;p&gt;and so specify the synchronization schedule for each agent.&lt;/p&gt;  &lt;p&gt;Schedules:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Run Continuously: add schedule times to be auto run continuously&lt;/li&gt;    &lt;li&gt;Run on demand only: manually run the synchronization&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnLjpN9_psI/AAAAAAAAA7A/5KNuM9B96zw/s1600-h/clip_image027%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image027" border="0" alt="clip_image027" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnLjp7fR_RI/AAAAAAAAA7E/ftxpxvWhg1w/clip_image027_thumb.jpg?imgmax=800" width="385" height="324" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;and then next up to final step, then click finish&lt;/p&gt;  &lt;p&gt;you can check the errors from &amp;quot;Replication Monitor&amp;quot; by right click on Local Replication --&amp;gt; Launch Replication Monitor&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Advantages in Replication:&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Users can avail the following advantages by using replication process:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Users working in different geographic locations can work with their local copy of data thus allowing greater autonomy.&lt;/li&gt;    &lt;li&gt;Database replication can also supplement your disaster-recovery plans by duplicating the data from a local database server to a remote database server. If the primary server fails, your applications can switch to the replicated copy of the data and continue operations.&lt;/li&gt;    &lt;li&gt;You can automatically back up a database by keeping a replica on a different computer. Unlike traditional backup methods that prevent users from getting access to a database during backup, replication allows you to continue making changes online.&lt;/li&gt;    &lt;li&gt;You can replicate a database on additional network servers and reassign users to balance the loads across those servers. You can also give users who need constant access to a database their own replica, thereby reducing the total network traffic.&lt;/li&gt;    &lt;li&gt;Database-replication logs the selected database transactions to a set of internal replication-management tables, which can then be synchronized to the source database. Database replication is different from file replication, which essentially copies files.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;b&gt;Replication Performance Tuning Tips:&lt;/b&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;By distributing partitions of data to different Subscribers.&lt;/li&gt;    &lt;li&gt;When running SQL Server replication on a dedicated server, consider setting the minimum memory amount for SQL Server to use from the default value of 0 to a value closer to what SQL Server normally uses.&lt;/li&gt;    &lt;li&gt;Don’t publish more data than you need. Try to use Row filter and Column filter options wherever possible as explained above.&lt;/li&gt;    &lt;li&gt;Avoid creating triggers on tables that contain subscribed data.&lt;/li&gt;    &lt;li&gt;Applications that are updated frequently are not good candidates for database replication.&lt;/li&gt;    &lt;li&gt;For best performance, avoid replicating columns in your publications that include TEXT, NTEXT or IMAGE data types.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href="http://www.codeproject.com/KB/database/sql2005-replication.aspx"&gt;Source&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-7753217174161685835?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/7753217174161685835/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2009/07/sql-server-2005-merge-replication-step.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/7753217174161685835'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/7753217174161685835'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2009/07/sql-server-2005-merge-replication-step.html' title='SQL Server 2005 - Merge Replication Step by Step Procedure'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_iuwZHhydmEs/SnLjPadL5sI/AAAAAAAAA5M/dkz9OcWlhyI/s72-c/clip_image002_thumb.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-5200844109377375611</id><published>2009-07-30T15:11:00.001-07:00</published><updated>2009-07-30T15:11:59.970-07:00</updated><title type='text'>Model View Presenter (MVP) design pattern and data binding</title><content type='html'>&lt;p&gt;&lt;b&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;a href="http://www.c-sharpcorner.com/UploadFile/john_charles/ModelViewPresenterdesignpatterndatabinding06032009090829AM/ModelViewPresenterdesignpatterndatabinding.aspx"&gt;Sourse Here&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Introduction&lt;/b&gt;    &lt;br /&gt;Model View Presenter (MVP) design pattern is the evolution of the MVC design pattern and it's aimed at providing a cleaner separation of concerns between the view, the model, and the controller improving the architecture (you can use several UI technologies without recompiling the business logic components) and testability of the enterprise solution. The pattern was originally developed at Taligent in the 1990s.    &lt;br /&gt;In this article, I will explain the principles and how to use the MVP design pattern along with data binding with an example using C# language in Microsoft.NET.    &lt;br /&gt;&lt;b&gt;The Model View Presenter (MVP) design pattern&lt;/b&gt;    &lt;br /&gt;Starting from the Model View Controller (MVC) design pattern, creators of MVP neatly separated the model from the view/controller pair. The core of MVP is the strictly regulated interaction taking place between the view and the controller. In MVP, this controller is renamed to presenter.    &lt;br /&gt;In the Figure 1, you can see an overview of the MVP design pattern.    &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnIaHCQiB2I/AAAAAAAAA3o/Mnq7gP3Wpp4/s1600-h/clip_image001%5B3%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image001" border="0" alt="clip_image001" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnIaKsJEv6I/AAAAAAAAA3s/7MbWmn-fm50/clip_image001_thumb.gif?imgmax=800" width="423" height="152" /&gt;&lt;/a&gt;    &lt;br /&gt;Figure 1    &lt;br /&gt;As you can see in the Figure 1, the view and model are neatly separated (they don't know each other) and the view exposes an interface for the &lt;a href="http://www.c-sharpcorner.com/UploadFile/john_charles/ModelViewPresenterdesignpatterndatabinding06032009090829AM/ModelViewPresenterdesignpatterndatabinding.aspx"&gt;communication&lt;/a&gt; of the presenter with the view and in this way the presenter doesn't know the underlying UI technology and the view is mockable for &lt;a href="http://www.c-sharpcorner.com/UploadFile/john_charles/ModelViewPresenterdesignpatterndatabinding06032009090829AM/ModelViewPresenterdesignpatterndatabinding.aspx"&gt;testing&lt;/a&gt; purposes. As well as the presenter knows the model and can invoke its operations.    &lt;br /&gt;Note that each Presenter object has exactly one reference to a View object, and each View object has exactly one reference to a Presenter object. There is one Model object for the whole application. As you can see it's required to define an interface and a presenter for every View object of your application (each Web form in ASP.NET and form in Windows).    &lt;br /&gt;Let's explain the MVP triad at a glance.     &lt;br /&gt;The Model represents the business objects of the domain problem. That is business entities encapsulating the data, business services implementing the business logic and rules of your solution. It's a domain object and should have no knowledge of the user interface, unlike previous design patterns such as MVC (Model-View-Controller) where the model implements the user interface to manipulate it which is a big design error if you try to separate the concerns of the domain.    &lt;br /&gt;The View is responsible to display the content of the model and interact with the user's events regarding the UI technology of the solution.    &lt;br /&gt;The Presenter is responsible to interpret the user's events and the communication with the model objects. It implements the main workflow of the application. This is where the heart of the application lies.    &lt;br /&gt;It's remarkable to say that Martin Fowler has extended the original MVP design pattern with Passive View and Supervising Controller/Presenter.    &lt;br /&gt;In the case of the Passive View pattern, the main idea is to have no dependencies between the View and the Model concerns and the view is dumb. The Supervising Controller is a flexible interpretation of the original MVP design pattern and the view is not completely dumb and has some responsibilities.    &lt;br /&gt;Now well, my approach, to architect an enterprise-class application for being implemented using Microsoft technologies, is to separate concerns in multiple layers and follow the MVP design patter along with data binding (data binding using BindingSource support in Windows &lt;a href="http://www.c-sharpcorner.com/UploadFile/john_charles/ModelViewPresenterdesignpatterndatabinding06032009090829AM/ModelViewPresenterdesignpatterndatabinding.aspx"&gt;applications&lt;/a&gt; and data binding with ObjectDataSource support in ASP.NET applications). The View has some responsibilities such as displaying, formatting and gathering data as well as handling user interaction's events. The Presenter has the responsibility to interpret the messages sent and received from the View as well as to invoke the underlying business objects in the business logic layer in the Model. Now, the communication between the layers of the application is through Data Transfer Objects (DTO). The use of DTO is trade-off because we create new DTO, we're increasing the cost of the complexity of the solution and this cost is justified in large enterprise applications. For small and medium application, it makes sense to reference the business objects directly from the View concern (and bind the data represented by the business object in the controls) in order to avoid the definition of new DTO. The idea is to use the data model represented by the business object as the DTO. But it's not correct to invoke operations and business logic directly from the View (data access methods, calculation, invocation of external services, etc).    &lt;br /&gt;The solution, which I will explain in this article, will be based on the MVP design pattern along with data binding for small enterprise application.    &lt;br /&gt;&lt;b&gt;Implementing the Model View Presenter (MVP) design pattern&lt;/b&gt;    &lt;br /&gt;Now let's go and implement the principles and concepts of the Model View Presenter (MVP) design pattern along with data binding in a multi-layer enterprise application using C# in Microsoft.NET.    &lt;br /&gt;Let's open the Visual Studio.NET 2008 IDE and create an example solution (see Figure 2).    &lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnIaNMfUhZI/AAAAAAAAA3w/9XZarRYR-MQ/s1600-h/clip_image002%5B3%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnIaPoOZhzI/AAAAAAAAA30/J4ty6xPFzVw/clip_image002_thumb.gif?imgmax=800" width="423" height="288" /&gt;&lt;/a&gt;    &lt;br /&gt;Figure 2    &lt;br /&gt;For this example, we're going to create an application which enables managing the contacts of one enterprise. The data source is the Person.Contact table in the AdventureWorks database shipped with SQL Server 2005.     &lt;br /&gt;Let's add the business logic layer using a Class Library project (see Figure 3).    &lt;br /&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnIaRqWRQtI/AAAAAAAAA34/96-DWDX7q6E/s1600-h/clip_image003%5B3%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image003" border="0" alt="clip_image003" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnIaSnWVaVI/AAAAAAAAA38/neRk6oARNbM/clip_image003_thumb.gif?imgmax=800" width="423" height="274" /&gt;&lt;/a&gt;    &lt;br /&gt;Figure 3    &lt;br /&gt;Next step is to add the business entities and objects which model your problem domain (see Listing 1). For the definition of the business entities we're going to use strongly typed Data Set and for the data access code we're going to rely on the underlying table adapters.    &lt;br /&gt;Let's add a DataSet to the project named DSContactManager as shown in the Figure 4.    &lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnIaTjZy5PI/AAAAAAAAA4A/JS4_62uuwKM/s1600-h/clip_image004%5B3%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnIaVhkVq-I/AAAAAAAAA4E/0ze5QO3pgHw/clip_image004_thumb.gif?imgmax=800" width="423" height="256" /&gt;&lt;/a&gt;    &lt;br /&gt;Figure 4    &lt;br /&gt;Let's add a Contact data table and its underlying table adapter (see Figure 5).    &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnIaWwh3emI/AAAAAAAAA4I/0Shlt9C0Nsk/s1600-h/clip_image005%5B3%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image005" border="0" alt="clip_image005" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnIaXw7PCcI/AAAAAAAAA4M/bIuNJBjSUIw/clip_image005_thumb.gif?imgmax=800" width="256" height="324" /&gt;&lt;/a&gt;    &lt;br /&gt;Figure 5    &lt;br /&gt;Now let's add the business service objects to implement the business logic concerning the Contact business entity (see Figure 6).    &lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnIaZEu4ycI/AAAAAAAAA4Q/sMVrTzYX8To/s1600-h/clip_image006%5B3%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnIaZ8f5xII/AAAAAAAAA4U/PQVTdJb7gFw/clip_image006_thumb.gif?imgmax=800" width="423" height="258" /&gt;&lt;/a&gt;    &lt;br /&gt;Figure 6    &lt;br /&gt;The code definition for the business services regarding the contact entity is the Listing 1.    &lt;br /&gt;using System;    &lt;br /&gt;using System.Collections.Generic;    &lt;br /&gt;using System.Linq;    &lt;br /&gt;using System.Text; &lt;/p&gt;  &lt;p&gt;namespace BusinessLogicPkg   &lt;br /&gt;{    &lt;br /&gt;public class ContactBizServices    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;private DSContactManager m_dsContact;&lt;/p&gt;  &lt;p&gt;public ContactBizServices(DSContactManager dsContact)   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;this.m_dsContact = dsContact;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;public void Load()   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DSContactManagerTableAdapters.ContactTableAdapter taContact = new BusinessLogicPkg.DSContactManagerTableAdapters.ContactTableAdapter();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; taContact.Fill(this.m_dsContact.Contact);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;public void Save()   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DSContactManagerTableAdapters.ContactTableAdapter taContact = new BusinessLogicPkg.DSContactManagerTableAdapters.ContactTableAdapter();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; taContact.Update(this.m_dsContact.Contact);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;}    &lt;br /&gt;&lt;b&gt;Listing 1&lt;/b&gt;    &lt;br /&gt;Now let's add the Presentation layer where the presenter objects lies using a Class Library project (see Figure 7).    &lt;br /&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnIabr-ZsGI/AAAAAAAAA4Y/z6tyi-Zrn2o/s1600-h/clip_image007%5B3%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image007" border="0" alt="clip_image007" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnIadV9tDQI/AAAAAAAAA4c/qO42fkTb1TY/clip_image007_thumb.gif?imgmax=800" width="423" height="257" /&gt;&lt;/a&gt;    &lt;br /&gt;Figure 7    &lt;br /&gt;We need to add a reference to the business logic layer in the PresentationLayer as in the Figure 8.    &lt;br /&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnIaeQ7sA-I/AAAAAAAAA4g/tGpkOdOd1Cg/s1600-h/clip_image008%5B3%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnIagOywpEI/AAAAAAAAA4k/uJk8v846aWQ/clip_image008_thumb.gif?imgmax=800" width="395" height="324" /&gt;&lt;/a&gt;    &lt;br /&gt;Figure 8    &lt;br /&gt;Next step is to add the ContactManagerPresenter class to handle the workflow for the communication between the UI controls and the model objects as well as to add the IContactManagerView interface to define the interface to be implemented by the underlying UI artifacts which need to communicate with the Presenter artifact.    &lt;br /&gt;In order to define the IContactManagerView interface, we deal with the user stories and requirements and in this case, we want to load contact data, to be changed and then save the changes. We need to access to the data model (the strongly typed Data Set DSContactManager) as the DTO and send a message to the user notifying the status of the performed operation (see Listing 2).    &lt;br /&gt;using System;    &lt;br /&gt;using System.Collections.Generic;    &lt;br /&gt;using System.Linq;    &lt;br /&gt;using System.Text;    &lt;br /&gt;using BusinessLogicPkg;&lt;/p&gt;  &lt;p&gt;namespace PresentationLayerPkg   &lt;br /&gt;{    &lt;br /&gt;public interface IContactManagerView    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;DSContactManager ContactManager { get; }    &lt;br /&gt;void SendMessageInfo(string strMessage);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;}    &lt;br /&gt;&lt;b&gt;Listing 2&lt;/b&gt;    &lt;br /&gt;Now let's define the workflow of the presenter object as shown in Listing 3.    &lt;br /&gt;using System;    &lt;br /&gt;using System.Collections.Generic;    &lt;br /&gt;using System.Linq;    &lt;br /&gt;using System.Text;    &lt;br /&gt;using BusinessLogicPkg;&lt;/p&gt;  &lt;p&gt;namespace PresentationLayerPkg   &lt;br /&gt;{    &lt;br /&gt;public class ContactManagerPresenter    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;private IContactManagerView m_objContactManagerView = null;&lt;/p&gt;  &lt;p&gt;public ContactManagerPresenter(IContactManagerView objContactManagerView)   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;this.m_objContactManagerView = objContactManagerView;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;public void LoadContact()   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;ContactBizServices objContactBizServices = new ContactBizServices(this.m_objContactManagerView.ContactManager);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; objContactBizServices.Load();    &lt;br /&gt;this.m_objContactManagerView.SendMessageInfo(&amp;quot;Operation has successfully ended&amp;quot;);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;public void SaveContact()   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;ContactBizServices objContactBizServices = new ContactBizServices(this.m_objContactManagerView.ContactManager);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; objContactBizServices.Save();    &lt;br /&gt;this.m_objContactManagerView.SendMessageInfo(&amp;quot;Operation has successfully ended&amp;quot;);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160; }   &lt;br /&gt;}    &lt;br /&gt;&lt;b&gt;Listing 3&lt;/b&gt;    &lt;br /&gt;Now let's go to the Windows Forms project to define the user interface and communication with the Presenter artifact.    &lt;br /&gt;Fist step is to add a reference to the PresentationLayerPkg library as shown in Figure 9.    &lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnIaiEBYj3I/AAAAAAAAA4o/Vc7KcN1tQGQ/s1600-h/clip_image009%5B3%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image009" border="0" alt="clip_image009" src="http://lh6.ggpht.com/_iuwZHhydmEs/SnIajo-lktI/AAAAAAAAA4s/_2lCtD-Wqmc/clip_image009_thumb.gif?imgmax=800" width="394" height="324" /&gt;&lt;/a&gt;    &lt;br /&gt;Figure 9    &lt;br /&gt;We need to a reference to the BusinessLogicPkg library as well because we're going to use the data model as our Data Transfer Object (DTO) (see Figure 10).    &lt;br /&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnIaks81NUI/AAAAAAAAA4w/V3a4kmFULJ0/s1600-h/clip_image010%5B3%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image010" border="0" alt="clip_image010" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnIamste8_I/AAAAAAAAA40/9UdfWE80oGw/clip_image010_thumb.gif?imgmax=800" width="394" height="324" /&gt;&lt;/a&gt;    &lt;br /&gt;Figure 10    &lt;br /&gt;Now let's add a data source object. Open the Data Sources window and click on the Add New Data Source link to open the Data Source Configuration Wizard. Then select the DSContactManager object in the BusinessLogicPkg library (see Figure 11).    &lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnIanDwwF0I/AAAAAAAAA44/1zb0OVo7Lfg/s1600-h/clip_image011%5B3%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image011" border="0" alt="clip_image011" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnIaoWBEPGI/AAAAAAAAA48/JkOIAGpsiis/clip_image011_thumb.gif?imgmax=800" width="414" height="324" /&gt;&lt;/a&gt;    &lt;br /&gt;Figure 11    &lt;br /&gt;Then drag and drop the defined data source onto the form as a grid control. This action adds a DataGrid control and a binding navigator control in the form. Delete the save icon on the binding navigator to do the load and save actions manually.    &lt;br /&gt;Next step is to drag and drop two buttons on the form (one to load the data and the other to save the date after changes) and the underlying event handlers.    &lt;br /&gt;Next step is to implement the view interface defined in the presenter library. We need to return an instance of the DSContactManager and show an information message (see Listing 4).    &lt;br /&gt;#region IContactManagerView Members&lt;/p&gt;  &lt;p&gt;public BusinessLogicPkg.DSContactManager ContactManager   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;get    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;return this.dSContactManager;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;public void SendMessageInfo(string strMessage)   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; System.Windows.Forms.MessageBox.Show(strMessage, &amp;quot;Information Message&amp;quot;, MessageBoxButtons.OK, MessageBoxIcon.Information);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; #endregion    &lt;br /&gt;&lt;b&gt;Listing 4&lt;/b&gt;    &lt;br /&gt;And the implementation of the event handlers is done by invoking the underlying methods in the presenter artifact (see Listing 5).    &lt;br /&gt;private void btnLoad_Click(object sender, EventArgs e)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;ContactManagerPresenter objContactManagerPresenter = new ContactManagerPresenter(this);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; objContactManagerPresenter.LoadContact();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;private void btnSave_Click(object sender, EventArgs e)   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;ContactManagerPresenter objContactManagerPresenter = new ContactManagerPresenter(this);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; objContactManagerPresenter.SaveContact();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&lt;b&gt;Listing 5&lt;/b&gt;    &lt;br /&gt;The complete code for the Windows forms is shown in the Listing 6.    &lt;br /&gt;using System;    &lt;br /&gt;using System.Collections.Generic;    &lt;br /&gt;using System.ComponentModel;    &lt;br /&gt;using System.Data;    &lt;br /&gt;using System.Drawing;    &lt;br /&gt;using System.Linq;    &lt;br /&gt;using System.Text;    &lt;br /&gt;using System.Windows.Forms;    &lt;br /&gt;using PresentationLayerPkg;&lt;/p&gt;  &lt;p&gt;namespace WinMVPDatabinding   &lt;br /&gt;{    &lt;br /&gt;public partial class Form1 : Form, IContactManagerView    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;public Form1()    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; InitializeComponent();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;private void btnLoad_Click(object sender, EventArgs e)   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;ContactManagerPresenter objContactManagerPresenter = new ContactManagerPresenter(this);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; objContactManagerPresenter.LoadContact();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;private void btnSave_Click(object sender, EventArgs e)   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;ContactManagerPresenter objContactManagerPresenter = new ContactManagerPresenter(this);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; objContactManagerPresenter.SaveContact();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; #region IContactManagerView Members&lt;/p&gt;  &lt;p&gt;public BusinessLogicPkg.DSContactManager ContactManager   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;get    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;return this.dSContactManager;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;public void SendMessageInfo(string strMessage)   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; System.Windows.Forms.MessageBox.Show(strMessage, &amp;quot;Information Message&amp;quot;, MessageBoxButtons.OK, MessageBoxIcon.Information);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; #endregion   &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;}    &lt;br /&gt;&lt;b&gt;Listing 6&lt;/b&gt;    &lt;br /&gt;The Figure 12 shows when you run the application.    &lt;br /&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnIapuoFDgI/AAAAAAAAA5A/7VrHebSEAR0/s1600-h/clip_image012%5B3%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image012" border="0" alt="clip_image012" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnIaq-378mI/AAAAAAAAA5E/MiXHjIuRwJE/clip_image012_thumb.gif?imgmax=800" width="423" height="230" /&gt;&lt;/a&gt;    &lt;br /&gt;Figure 12    &lt;br /&gt;&lt;b&gt;Conclusion&lt;/b&gt;    &lt;br /&gt;In this article, I've explained the concepts of the Model View Presenter (MVP) design pattern along with data binding through an example.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-5200844109377375611?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/5200844109377375611/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2009/07/model-view-presenter-mvp-design-pattern.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/5200844109377375611'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/5200844109377375611'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2009/07/model-view-presenter-mvp-design-pattern.html' title='Model View Presenter (MVP) design pattern and data binding'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_iuwZHhydmEs/SnIaKsJEv6I/AAAAAAAAA3s/7MbWmn-fm50/s72-c/clip_image001_thumb.gif?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-6979613141063042586</id><published>2009-07-30T15:07:00.001-07:00</published><updated>2009-07-30T15:07:31.133-07:00</updated><title type='text'>One way, two way and one time bindings using Silverlight</title><content type='html'>&lt;h4&gt;&lt;a name="Introduction"&gt;Introduction&lt;/a&gt;&lt;/h4&gt;  &lt;p&gt;&lt;a href="http://www.c-sharpcorner.com/UploadFile/shivprasadk/SilverlightBindings06152009035018AM/SilverlightBindings.aspx"&gt;Source Here&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This article will talk about three ways of binding object properties with SilverLight &lt;a href="http://www.c-sharpcorner.com/UploadFile/shivprasadk/SilverlightBindings06152009035018AM/SilverlightBindings.aspx#"&gt;user interfaces&lt;/a&gt;.&amp;#160; We will first go through the fundamentals of the 3 bindings and then take up a small sample which will demonstrate how the binding works. We have also attached the source for the same.&lt;/p&gt;  &lt;h4&gt;&lt;a name="OtherSilverlightFAQ"&gt;Other Silverlight FAQ&lt;/a&gt;&lt;/h4&gt;  &lt;p&gt;In case you are a complete fresher to silverlight then below are some silverlight FAQ's&amp;#160; which can give you a quick start in this topic. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;Silverlight FAQ Part 1&lt;/b&gt;:- &lt;a href="http://www.c-sharpcorner.com/UploadFile/shivprasadk/21FAQ04242009031713AM/21FAQ.aspx"&gt;For article click here&lt;/a&gt;&amp;#160; This tutorial has 21 basic FAQ's which will help you understand WPF, XAML, help your build your first silverlight &lt;a href="http://www.c-sharpcorner.com/UploadFile/shivprasadk/SilverlightBindings06152009035018AM/SilverlightBindings.aspx#"&gt;application&lt;/a&gt; and also explains the overall silverlight architecture. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;SilverLight FAQ Part 2 (Animations and Transformations):-&lt;/b&gt; &lt;a href="http://www.c-sharpcorner.com/UploadFile/shivprasadk/333333306012009030039AM/3333333.aspx"&gt;For article click here&lt;/a&gt; This tutorial has 10 FAQ questions which starts with silverlight animation fundamentals and then shows a simple animated rectangle. The article then moves ahead and talks about 4 different ways of transforming the objects.&amp;#160; &lt;/p&gt;  &lt;h4&gt;&lt;a name="_Toc232743057"&gt;One way bindings&lt;/a&gt;&lt;/h4&gt;  &lt;p&gt;As the name so the behavior. In one way bindings data flows only from object to UI and not vice-versa. For instance you can have a textbox called as 'TxtYear' which is binded with an object having property 'Year'. So when the object value changes it will be reflected on the silverlight UI, but the UI cannot update the year property in the object. &lt;/p&gt;  &lt;p&gt;&lt;img border="0" alt="1.JPG" align="left" src="http://www.c-sharpcorner.com/UploadFile/shivprasadk/SilverlightBindings06152009035018AM/Images/1.JPG" width="393" height="179" /&gt;&lt;/p&gt;  &lt;p&gt;It is a three step procedure to implement one way binding. First create your class which you want to bind with the silverlight UI.&amp;#160; For instance below is a simple class called as 'ClsDate' with a 'Year' property.&lt;/p&gt;  &lt;p&gt;public class clsDate   &lt;br /&gt;{    &lt;br /&gt;private int _intYear;    &lt;br /&gt;public int Year    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;set    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _intYear = value;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;get    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;return _intYear;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;In the second step you need to tie up the 'Year' property with a silver light UI text box. To bind the property you need to specify 'Binding Path=Year' in the text property of the text box UI object. 'Year' is the property which we are binding with the text box UI object.&lt;/p&gt;  &lt;p&gt;&amp;lt;TextBox x:Name=&amp;quot;txtCurrentYear&amp;quot; Text=&amp;quot;{Binding Path=Year}&amp;quot; Height=&amp;quot;30&amp;quot; Width=&amp;quot;150&amp;quot; VerticalAlignment=&amp;quot;Center&amp;quot; HorizontalAlignment=&amp;quot;Center&amp;quot;&amp;gt;&amp;lt;/TextBox&amp;gt;&lt;/p&gt;  &lt;p&gt;The final step is to bind the text box data context with the date object just created.&lt;/p&gt;  &lt;p&gt;public partial class Page : UserControl   &lt;br /&gt;{    &lt;br /&gt;public Page()    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; InitializeComponent();    &lt;br /&gt;clsDate objDate = new clsDate();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; objDate.Year = DateTime.Now.Year;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; txtCurrentYear.DataContext = objDate;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;}&lt;/p&gt;  &lt;h4&gt;&lt;a name="Twowaybinding"&gt;Two way binding&lt;/a&gt;&lt;/h4&gt;  &lt;h4&gt;Two way binding ensure &lt;a href="http://www.c-sharpcorner.com/UploadFile/shivprasadk/SilverlightBindings06152009035018AM/SilverlightBindings.aspx#"&gt;data synchronization&lt;/a&gt; of data between UI and Objects. So any change in object is reflected to the UI and any change in UI is reflected in the object. &lt;/h4&gt;  &lt;p&gt;&lt;img border="0" alt="2.JPG" src="http://www.c-sharpcorner.com/UploadFile/shivprasadk/SilverlightBindings06152009035018AM/Images/2.JPG" width="409" height="187" /&gt;    &lt;br /&gt;To implement two way binding there are two extra steps with addition to the steps provided for 'OneWay'. The first change is we need to specify the mode as 'TwoWay' as shown in the below XAML code snippet.&lt;/p&gt;  &lt;p&gt;&amp;lt;TextBox x:Name=&amp;quot;txtEnterAge&amp;quot; Text=&amp;quot;{Binding Path=Age, Mode=TwoWay}&amp;quot; Height=&amp;quot;30&amp;quot; Width=&amp;quot;150&amp;quot; VerticalAlignment=&amp;quot;Center&amp;quot; HorizontalAlignment=&amp;quot;Center&amp;quot;&amp;gt;&amp;lt;/TextBox&amp;gt;&lt;/p&gt;  &lt;p&gt;Second change is we need to implement 'INotifyPropertyChanged' interface. Below is the class which shows how to implement the 'INotifyPropertyChanged' interface. Please note you need to import 'System.ComponentModel' namespace.&lt;/p&gt;  &lt;p&gt;public class clsDate : INotifyPropertyChanged   &lt;br /&gt;{    &lt;br /&gt;public event PropertyChangedEventHandler PropertyChanged;    &lt;br /&gt;private int _intYear;    &lt;br /&gt;public int Year    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;set    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _intYear = value;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; OnPropertyChanged(&amp;quot;Year&amp;quot;);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;get    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;return _intYear;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;private void OnPropertyChanged(string property)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;if (PropertyChanged != null)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; PropertyChanged(this,new PropertyChangedEventArgs(property));    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;The binding of data with data context is a compulsory step which needs to be performed. &lt;/p&gt;  &lt;h4&gt;&lt;a name="Onetimebinding"&gt;One time binding&lt;/a&gt;&lt;/h4&gt;  &lt;h4&gt;In one time binding data flows from object to the UI only once. There is no tracking mechanism to update data on either side. One time binding has marked performance improvement as compared to the previous two bindings discussed. This binding is a good choice for reports where the data is loaded only once and viewed. &lt;/h4&gt;  &lt;p&gt;&amp;lt;TextBox x:Name=&amp;quot;txtEnterAge&amp;quot; Text=&amp;quot;{Binding Path=Age, Mode=OneTime}&amp;quot; Height=&amp;quot;30&amp;quot; Width=&amp;quot;150&amp;quot;   &lt;br /&gt; VerticalAlignment=&amp;quot;Center&amp;quot; HorizontalAlignment=&amp;quot;Center&amp;quot;&amp;gt;&amp;lt;/TextBox&amp;gt;&lt;/p&gt;  &lt;h4&gt;&lt;a name="SimpledemonstrationofOneWayandTwoWay"&gt;Simple demonstration of OneWay and TwoWay&lt;/a&gt;&lt;/h4&gt;  &lt;p&gt;Below is a simple sample code where in we have two text boxes one takes in the age and the other text box calculates the approximate birth date. &lt;/p&gt;  &lt;p&gt;&lt;img border="0" alt="3.JPG" src="http://www.c-sharpcorner.com/UploadFile/shivprasadk/SilverlightBindings06152009035018AM/Images/3.JPG" width="445" height="229" /&gt;&lt;/p&gt;  &lt;p&gt;Below is a simple class which has both the properties. We have implemented 'INotifyPropertyChanged' interface so that we can have two way communication for the year property. &lt;/p&gt;  &lt;p&gt;using System;   &lt;br /&gt;using System.Net;    &lt;br /&gt;using System.Windows;    &lt;br /&gt;using System.Windows.Controls;    &lt;br /&gt;using System.Windows.Documents;    &lt;br /&gt;using System.Windows.Ink;    &lt;br /&gt;using System.Windows.Input;    &lt;br /&gt;using System.Windows.Media;    &lt;br /&gt;using System.Windows.Media.Animation;    &lt;br /&gt;using System.Windows.Shapes;    &lt;br /&gt;using System.ComponentModel;    &lt;br /&gt;namespace SilverLightBinding     &lt;br /&gt;{    &lt;br /&gt;public class clsDate : INotifyPropertyChanged    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;public event PropertyChangedEventHandler PropertyChanged;    &lt;br /&gt;private int _intYear;    &lt;br /&gt;private int _intAge;    &lt;br /&gt;public int Year    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;set    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _intYear = value;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; OnPropertyChanged(&amp;quot;Year&amp;quot;);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;get    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;return _intYear;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;public int Age    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;set    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _intAge = value;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Year = DateTime.Now.Year - _intAge;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;get    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;return _intAge;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;private void OnPropertyChanged(string property)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;if (PropertyChanged != null)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; PropertyChanged(this,    &lt;br /&gt;new PropertyChangedEventArgs(property));    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;Finally we have also binded the SilverLight UI objects with the class properties.&amp;#160; Below is the XAML snippet for the same. One point to be noted is that 'Age' is bounded using two way mode as we need to modify the same from the user interface.&lt;/p&gt;  &lt;p&gt;&amp;lt;TextBlock VerticalAlignment=&amp;quot;Center&amp;quot; HorizontalAlignment=&amp;quot;Center&amp;quot;&amp;gt; Enter your age in the below text box&amp;lt;/TextBlock&amp;gt;   &lt;br /&gt;&amp;lt;TextBox x:Name=&amp;quot;txtEnterAge&amp;quot; Text=&amp;quot;{Binding Path=Age, Mode=TwoWay}&amp;quot; Height=&amp;quot;30&amp;quot; Width=&amp;quot;150&amp;quot; VerticalAlignment=&amp;quot;Center&amp;quot; HorizontalAlignment=&amp;quot;Center&amp;quot;&amp;gt;&amp;lt;/TextBox&amp;gt;    &lt;br /&gt;&amp;lt;TextBlock VerticalAlignment=&amp;quot;Center&amp;quot; HorizontalAlignment=&amp;quot;Center&amp;quot;&amp;gt;Your approximate birth date&amp;lt;/TextBlock&amp;gt;    &lt;br /&gt;&amp;lt;TextBox x:Name=&amp;quot;txtCurrentYear&amp;quot; Text=&amp;quot;{Binding Path=Year}&amp;quot; Height=&amp;quot;30&amp;quot; Width=&amp;quot;150&amp;quot; VerticalAlignment=&amp;quot;Center&amp;quot; HorizontalAlignment=&amp;quot;Center&amp;quot;&amp;gt;&amp;lt;/TextBox&amp;gt;&lt;/p&gt;  &lt;p&gt;At the top of this article you can get the Source Code. &lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-6979613141063042586?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/6979613141063042586/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2009/07/one-way-two-way-and-one-time-bindings.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/6979613141063042586'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/6979613141063042586'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2009/07/one-way-two-way-and-one-time-bindings.html' title='One way, two way and one time bindings using Silverlight'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-8387051868182125726</id><published>2009-07-30T15:02:00.001-07:00</published><updated>2009-07-30T15:02:38.091-07:00</updated><title type='text'>Blocking IP Addresses Using MMC</title><content type='html'>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I was searching for a solution to block any communication with specific IP addresses. I have come to this solution using MMC (Microsoft Management Console). The following steps will allow you to block any communication - whatever the protocol is - with specific IP addresses or subnet:   &lt;br /&gt;1. Open Start Manu &amp;gt; Run &amp;gt; Write &amp;quot;MMC&amp;quot;. Then press Enter.    &lt;br /&gt;2. In the Management Console &amp;gt; File &amp;gt; Add/Remove Snap-in...    &lt;br /&gt;3. In the opened dialog, leave &amp;quot;Local Computer&amp;quot; as it's and click &amp;quot;Finish&amp;quot;.    &lt;br /&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/SnIYMA6ByjI/AAAAAAAAA3I/dvWGwuHT384/s1600-h/clip_image002%5B5%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://lh3.ggpht.com/_iuwZHhydmEs/SnIYOH2o8tI/AAAAAAAAA3M/c7JKZ3ID2lY/clip_image002_thumb%5B2%5D.gif?imgmax=800" width="626" height="432" /&gt;&lt;/a&gt;    &lt;br /&gt;4. You will have a new node in the left tree called: &amp;quot;IP Secuirty Policies in Local Computer&amp;quot;.    &lt;br /&gt;5. Right click on this node and select &amp;quot;Create IP Security Policy&amp;quot;.    &lt;br /&gt;6. In the opened dialog, write &amp;quot;Block IP&amp;quot;.    &lt;br /&gt;7. Click Next till the end of the wizard and then &amp;quot;Finish&amp;quot;.    &lt;br /&gt;8. You will have an item in the left pane called: &amp;quot;Block IP&amp;quot;. Right click on it and select &amp;quot;Properties&amp;quot;.    &lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SnIYQ5bZsKI/AAAAAAAAA3Q/Y8vUZA6NOd0/s1600-h/clip_image004%5B3%5D.jpg"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnIYTL8eX3I/AAAAAAAAA3U/pBSJHU88acE/clip_image004_thumb.jpg?imgmax=800" width="423" height="298" /&gt;&lt;/a&gt;    &lt;br /&gt;9. In the opened dialog, click &amp;quot;Add&amp;quot;.    &lt;br /&gt;10. Go through the wizard, till you reach a step called: &amp;quot;IP Filter List&amp;quot;.    &lt;br /&gt;11. Click &amp;quot;Add&amp;quot;. IP Filter Dialog will open.    &lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/SnIYU7fLpCI/AAAAAAAAA3Y/YQ_2DX-DOBM/s1600-h/clip_image006%5B5%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://lh5.ggpht.com/_iuwZHhydmEs/SnIYW3WX8AI/AAAAAAAAA3c/1fxuqXP4kEk/clip_image006_thumb%5B2%5D.gif?imgmax=800" width="681" height="527" /&gt;&lt;/a&gt;    &lt;br /&gt;12. Modify the name of your IP Filter and click &amp;quot;Add&amp;quot; to add an IP filter policy.    &lt;br /&gt;13. Click &amp;quot;Next. Leave &amp;quot;Source Address&amp;quot; as &amp;quot;My IP Address&amp;quot;.    &lt;br /&gt;14. In the destination address, you can select &amp;quot;A specific IP Address&amp;quot;. You can also filter by DNS or subnet. Enter the IP address to block. Then click Next.    &lt;br /&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/SnIYYws8o4I/AAAAAAAAA3g/Qkzo-wnldOM/s1600-h/clip_image008%5B7%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://lh4.ggpht.com/_iuwZHhydmEs/SnIYe9ReCcI/AAAAAAAAA3k/B93He1oNw4M/clip_image008_thumb%5B4%5D.gif?imgmax=800" width="848" height="686" /&gt;&lt;/a&gt;    &lt;br /&gt;15. Leave the protocol to be &amp;quot;Any&amp;quot; and click &amp;quot;Next&amp;quot;.    &lt;br /&gt;16. Then click &amp;quot;Finish&amp;quot;.    &lt;br /&gt;17. Apply all changes, and close all the opened windows. You may have to add &amp;quot;Block&amp;quot; action if it doesn't exist.    &lt;br /&gt;18. After you finish, don't forget to write click on &amp;quot;Block IP&amp;quot; policy and select &amp;quot;Assign&amp;quot;.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-8387051868182125726?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/8387051868182125726/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2009/07/blocking-ip-addresses-using-mmc.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/8387051868182125726'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/8387051868182125726'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2009/07/blocking-ip-addresses-using-mmc.html' title='Blocking IP Addresses Using MMC'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_iuwZHhydmEs/SnIYOH2o8tI/AAAAAAAAA3M/c7JKZ3ID2lY/s72-c/clip_image002_thumb%5B2%5D.gif?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-1962103263987862803</id><published>2009-07-29T00:43:00.001-07:00</published><updated>2009-07-29T00:43:07.582-07:00</updated><title type='text'>Use Gmail IMAP in Microsoft Outlook 2007</title><content type='html'>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;We’ve all been hearing about the new IMAP support in Gmail, but how do we access that from Outlook? Those of you that have been waiting patiently will be happy to know all the instructions are on this page.&lt;/p&gt;  &lt;p&gt;Using IMAP we can synchronize email across multiple devices, since the mail stays on the server. You already stopped reading this part and skipped down to the instructions, didn’t you?&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Enable IMAP in Gmail Settings&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Open your Settings panel in Gmail, and then click on the “Forwarding and POP/IMAP” tab.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/Sm_9CFemaBI/AAAAAAAAA08/Ya3cvZSRZoM/s1600-h/clip_image002%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://lh6.ggpht.com/_iuwZHhydmEs/Sm_9DFFeCoI/AAAAAAAAA1A/t9M4sBxjfms/clip_image002_thumb%5B1%5D.gif?imgmax=800" width="386" height="76" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now click the Enable IMAP radio button, and click Save Changes.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/Sm_9D4U1K2I/AAAAAAAAA1E/r8drZucQTj0/s1600-h/clip_image004%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://lh5.ggpht.com/_iuwZHhydmEs/Sm_9FCtVFjI/AAAAAAAAA1I/SDamPd0oP8E/clip_image004_thumb%5B1%5D.gif?imgmax=800" width="516" height="155" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Add Account to Outlook&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Use the Tools menu you to open the Account Settings panel.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/Sm_9GEsIhgI/AAAAAAAAA1M/Zw3gxmTWzKw/s1600-h/clip_image006%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image006" border="0" alt="clip_image006" src="http://lh6.ggpht.com/_iuwZHhydmEs/Sm_9HHL6WGI/AAAAAAAAA1Q/77mHwRUAhh0/clip_image006_thumb%5B1%5D.gif?imgmax=800" width="263" height="410" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If this is your first account you’ll be prompted for the wizard, otherwise you’ll need to click the New button under the E-mail tab.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/Sm_9Hzj6QKI/AAAAAAAAA1U/M64fk4JsOEw/s1600-h/clip_image008%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image008" border="0" alt="clip_image008" src="http://lh4.ggpht.com/_iuwZHhydmEs/Sm_9I_lV31I/AAAAAAAAA1Y/V4dDGriE14w/clip_image008_thumb%5B1%5D.gif?imgmax=800" width="426" height="300" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now select the “Microsoft Exchange, POP3, IMAP or HTTP” option and hit next.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/Sm_9JmQU0OI/AAAAAAAAA1c/-TffatnDEus/s1600-h/clip_image010%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image010" border="0" alt="clip_image010" src="http://lh5.ggpht.com/_iuwZHhydmEs/Sm_9K_kefJI/AAAAAAAAA1g/kk6Jg95dKyM/clip_image010_thumb%5B1%5D.gif?imgmax=800" width="466" height="149" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Select the checkbox for “Manually configure server settings” and everything on that page will gray out. Hit the next button again.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/Sm_9LvzhGpI/AAAAAAAAA1k/8mwhn6-gVbs/s1600-h/clip_image012%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image012" border="0" alt="clip_image012" src="http://lh5.ggpht.com/_iuwZHhydmEs/Sm_9MnDr8RI/AAAAAAAAA1o/1QdNuixI8XY/clip_image012_thumb%5B1%5D.gif?imgmax=800" width="504" height="119" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now select “Internet E-mail”&amp;#160; (Didn’t we just do this? This wizard is taking too long…)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/Sm_9NYol0yI/AAAAAAAAA1s/fED37Xmc8e4/s1600-h/clip_image014%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image014" border="0" alt="clip_image014" src="http://lh5.ggpht.com/_iuwZHhydmEs/Sm_9OIs57nI/AAAAAAAAA1w/HT6h61tRF7I/clip_image014_thumb%5B1%5D.gif?imgmax=800" width="490" height="153" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Finally we can enter some settings! Add in all your personal information here.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/Sm_9PESe01I/AAAAAAAAA10/egQ_OTXnMZo/s1600-h/clip_image016%5B6%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image016" border="0" alt="clip_image016" src="http://lh6.ggpht.com/_iuwZHhydmEs/Sm_9QGqKMqI/AAAAAAAAA14/X2NtpXh7ipo/clip_image016_thumb%5B3%5D.gif?imgmax=800" width="522" height="413" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Note: If you are outside of the US you may need to use imap.googlemail.com and smtp.googlemail.com instead of imap.gmail.com and smtp.gmail.com.&lt;/p&gt;  &lt;p&gt;Note: for Gmail Apps accounts, you’ll need to put in your full email address wherever you see an @gmail.com above. For instance, if your account was geek@howtogeek.com you would put that in the E-mail address field as well as the User Name field.&lt;/p&gt;  &lt;p&gt;Click on the “More Settings” button and find the Outgoing Server tab, where you’ll need to check the box for “My outgoing server requires authentication”&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/Sm_9RdDK08I/AAAAAAAAA18/cEedTZBAuHA/s1600-h/clip_image018%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image018" border="0" alt="clip_image018" src="http://lh5.ggpht.com/_iuwZHhydmEs/Sm_9SGCZb4I/AAAAAAAAA2A/iJJd_wRX59o/clip_image018_thumb%5B1%5D.gif?imgmax=800" width="545" height="189" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now choose the Advanced tab, and enter the following values (Very important)&lt;/p&gt;  &lt;p&gt;· Incoming Server: 993&lt;/p&gt;  &lt;p&gt;· Incoming Server encrypted connection: SSL&lt;/p&gt;  &lt;p&gt;· Outgoing Server: 587&lt;/p&gt;  &lt;p&gt;· Outgoing Server encrypted connection: TLS&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/Sm_9TC7egtI/AAAAAAAAA2E/uKdyYx2vcJs/s1600-h/clip_image020%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image020" border="0" alt="clip_image020" src="http://lh6.ggpht.com/_iuwZHhydmEs/Sm_9T-DjGuI/AAAAAAAAA2I/99LT5OB-F2Y/clip_image020_thumb%5B1%5D.gif?imgmax=800" width="494" height="281" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Note: If you are having an issue with your sent email not showing up in Gmail, you can use the Folders tab, and then select the [Gmail] \ Sent Mail folder.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Note&lt;/b&gt;: Only do this step if your mail is not showing up, otherwise it will duplicate the sent mail.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/Sm_9UwRvNsI/AAAAAAAAA2M/YJW1600NHIA/s1600-h/clip_image022%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image022" border="0" alt="clip_image022" src="http://lh5.ggpht.com/_iuwZHhydmEs/Sm_9V_yaQKI/AAAAAAAAA2Q/Z0yGXn6zT3Y/clip_image022_thumb%5B1%5D.gif?imgmax=800" width="353" height="380" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now that you’ve closed out that dialog, you can click the Test Account Settings button to make sure everything is going to work.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/Sm_9W6cQ_iI/AAAAAAAAA2Y/Sg4WUYmtVkY/s1600-h/clip_image024%5B5%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image024" border="0" alt="clip_image024" src="http://lh6.ggpht.com/_iuwZHhydmEs/Sm_9XwKLaPI/AAAAAAAAA2c/Ezytnsc99eo/clip_image024_thumb%5B2%5D.gif?imgmax=800" width="429" height="242" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;If all goes well, you should see a success message.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/Sm_9Yj7nlNI/AAAAAAAAA2g/Yfqp9fNdwpk/s1600-h/clip_image026%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image026" border="0" alt="clip_image026" src="http://lh6.ggpht.com/_iuwZHhydmEs/Sm_9Zio0OqI/AAAAAAAAA2k/9o9iiZSOtow/clip_image026_thumb%5B1%5D.gif?imgmax=800" width="425" height="238" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Note: Some ISPs restrict outgoing mail, so if you have a problem sending a test message you’ll need to consult with their documentation.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Accessing Your Mail&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Now that everything is working you’ll notice a new set of folders for your Gmail account. (I’m using Gmail apps, which is why you don’t see an @gmail.com email address)&lt;/p&gt;  &lt;p&gt;All of your labels will show up as separate folders, and the built-in “folders” in Gmail will be under the new [Gmail] folder.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/Sm_9aVBHZtI/AAAAAAAAA2o/PiYdmmG6zqg/s1600-h/clip_image028%5B3%5D.gif"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image028" border="0" alt="clip_image028" src="http://lh6.ggpht.com/_iuwZHhydmEs/Sm_9bkqkXCI/AAAAAAAAA2s/JH22WvSEWaw/clip_image028_thumb.gif?imgmax=800" width="221" height="236" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Outlook Flags = Gmail Stars&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;If you want to star a message in Gmail, you just need to flag it in Outlook. When I flagged this message from Mysticgeek…&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh5.ggpht.com/_iuwZHhydmEs/Sm_9cFfJtaI/AAAAAAAAA2w/Irt_k_lcOAA/s1600-h/clip_image030%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image030" border="0" alt="clip_image030" src="http://lh5.ggpht.com/_iuwZHhydmEs/Sm_9db8EsfI/AAAAAAAAA20/W_asgnGbzzg/clip_image030_thumb%5B1%5D.gif?imgmax=800" width="466" height="121" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;It shows up in Gmail as a starred message. (And it works the other way too)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_iuwZHhydmEs/Sm_9fiboFTI/AAAAAAAAA24/Lkn0Alv0mZA/s1600-h/clip_image032%5B5%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image032" border="0" alt="clip_image032" src="http://lh6.ggpht.com/_iuwZHhydmEs/Sm_9gv3IhSI/AAAAAAAAA28/Ah3_DJbgTUk/clip_image032_thumb%5B2%5D.gif?imgmax=800" width="477" height="140" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Sending Email from Outlook&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;To send a new email from your Gmail account, just change the “Account” drop-down to your Gmail address before you send a message.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_iuwZHhydmEs/Sm_9hfSX-wI/AAAAAAAAA3A/2Zs6eK8nBEg/s1600-h/clip_image034%5B4%5D.gif"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="clip_image034" border="0" alt="clip_image034" src="http://lh5.ggpht.com/_iuwZHhydmEs/Sm_9iS48P2I/AAAAAAAAA3E/k6DpV0HnowI/clip_image034_thumb%5B1%5D.gif?imgmax=800" width="427" height="251" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Note that if you only use Gmail, you won’t have this drop-down and it will default to your Gmail.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Final Thoughts&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Here’s a few things to keep in mind:&lt;/p&gt;  &lt;p&gt;· Gmail Labels = Outlook Folders. To label a message, add it to a folder.&lt;/p&gt;  &lt;p&gt;· Gmail Stars = Outlook Flags.&lt;/p&gt;  &lt;p&gt;· Do Not move spam messages to the “Junk E-mail” folder in Outlook, move them to the [Gmail] \ Spam folder.&lt;/p&gt;  &lt;p&gt;· Outlook has a built-in Search Folder for “Large Mail”, which will let you easily find messages with large attachments.&lt;/p&gt;  &lt;p&gt;Now that you can access your starred and labeled messages, you can start using Outlook’s excellent Search Folders to find messages more easily.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-1962103263987862803?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/1962103263987862803/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2009/07/use-gmail-imap-in-microsoft-outlook.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/1962103263987862803'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/1962103263987862803'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2009/07/use-gmail-imap-in-microsoft-outlook.html' title='Use Gmail IMAP in Microsoft Outlook 2007'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_iuwZHhydmEs/Sm_9DFFeCoI/AAAAAAAAA1A/t9M4sBxjfms/s72-c/clip_image002_thumb%5B1%5D.gif?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-542832273974411059</id><published>2009-07-12T19:54:00.000-07:00</published><updated>2009-07-12T18:53:36.185-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Miscellaneous'/><category scheme='http://www.blogger.com/atom/ns#' term='Tricks'/><title type='text'>Chapter 8 Continued: Caching Client/Server Applications</title><content type='html'>&lt;meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" /&gt;&lt;meta name="collection" content="learning" /&gt;&lt;meta name="keywords" content="programming, advanced, Java, 2" /&gt;&lt;meta name="description" content="Caching is one of the first techniques used to improve the performance of web browsers and web servers. The browser cache makes network lookup operations unnecessary because a recent copy of the file is kept in the local cache, and the web server cache reduces the cost of loading the file from disk for each request. This section explains how you can use caching in a similar way to improve performance in many client/server applications written in the Java programming language." /&gt;&lt;meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" /&gt;&lt;meta name="archive" content="false" /&gt;&lt;meta name="date" content="2003-03-22" /&gt;&lt;link rel="stylesheet" href="/css/default_developer.css" /&gt;&lt;script type="text/javascript" language="JavaScript" src="/js/popUp.js"&gt;&lt;/script&gt;&lt;script language="javascript1.2" type="text/javascript" src="/js/sniff.js"&gt;&lt;/script&gt;&lt;script language="javascript1.2" type="text/javascript" src="/js/menucontent.js"&gt;&lt;/script&gt;&lt;!-- END A2 COMPONENT V.1 --&gt;&lt;!-- END GENERIC MASTHEAD --&gt;&lt;!-- BEGIN BREADCRUMB --&gt;  &lt;table class="vatop" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td&gt;         &lt;div class="breadcrumb"&gt;&lt;/div&gt;       &lt;/td&gt;        &lt;td nowrap="nowrap" align="right"&gt;         &lt;div class="breadcrumb"&gt;&lt;/div&gt;       &lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td colspan="2"&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;div class="smallpagetitle"&gt;   &lt;table border="0" cellspacing="0" cellpadding="10" width="100%"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="100%"&gt;           &lt;p&gt;&amp;#160;&lt;/p&gt;            &lt;p&gt;Caching is one of the first techniques used to improve the performance of web browsers and web servers. The browser cache makes network lookup operations unnecessary because a recent copy of the file is kept in the local cache, and the web server cache reduces the cost of loading the file from disk for each request. This section explains how you can use caching in a similar way to improve performance in many client/server applications written in the Java programming language. &lt;/p&gt;            &lt;p&gt;The &lt;code&gt;java.util.Collections&lt;/code&gt; API available in the Java® 2 Software Development Kit (SDK) software makes implementing a cache simple. This API provides the &lt;code&gt;HashMap&lt;/code&gt; class, which works well for caching one object, and the &lt;code&gt;LinkedList&lt;/code&gt; class, which works well in combination with the &lt;code&gt;HashMap&lt;/code&gt; class for caching many objects. &lt;/p&gt;            &lt;ul&gt;             &lt;li&gt;&lt;a href="#one"&gt;Caching One Object&lt;/a&gt; &lt;/li&gt;              &lt;li&gt;&lt;a href="#more"&gt;Caching Many Objects&lt;/a&gt; &lt;/li&gt;           &lt;/ul&gt; &lt;!-- BEGIN FRAGMENT | HR TAG --&gt;            &lt;div class="contentdivider"&gt;             &lt;table class="grey4" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;                 &lt;tr&gt;                   &lt;td&gt;&lt;img border="0" alt=" " src="/im/a.gif" width="1" height="4" /&gt;&lt;/td&gt;                 &lt;/tr&gt;               &lt;/tbody&gt;&lt;/table&gt;           &lt;/div&gt; &lt;!-- END FRAGMENT | HR TAG --&gt;&lt;a name="one"&gt;&lt;/a&gt;            &lt;p&gt;&lt;b&gt;Caching One Object&lt;/b&gt; &lt;/p&gt;            &lt;p&gt;A &lt;code&gt;HashMap&lt;/code&gt; object stores data in key and value pairs. When you put a data value in the &lt;code&gt;HashMap&lt;/code&gt;, you assign it a key and later use that key to retrieve the data. &lt;/p&gt;            &lt;p&gt;A &lt;code&gt;HashMap&lt;/code&gt; object is very similar to a &lt;code&gt;Hashtable&lt;/code&gt; and can be used to keep a temporary copy of previously generated results. Objects kept in the &lt;code&gt;HashMap&lt;/code&gt; cache could, for example, be a list of completed auction results. &lt;/p&gt;            &lt;p&gt;In this case, the results of a JDBC query might be requested hundreds of times a second by persons wanting to know who was the highest bidder, but the completed results lists only actually changes once a minute as each auction completes. You can write your program to retrieve unchanged objects from the results cache instead of querying the database every time and gain a significant performance improvement. &lt;/p&gt;            &lt;p&gt;This &lt;a href="/developer/onlineTraining/Programming/JDCBook/Code/DBCache.java"&gt;code example&lt;/a&gt; runs a database query once a minute, and returns cached copies for requests that come between the queries. &lt;/p&gt; &lt;!-- BEGIN VCD7 CODE SAMPLE COMPONENT  --&gt;            &lt;table class="grey4" border="0" cellspacing="0" cellpadding="10" width="100%"&gt;&lt;tbody&gt;               &lt;tr&gt;                 &lt;td&gt;                   &lt;pre&gt; &lt;br /&gt;import java.util.*;&lt;br /&gt;import java.io.*;&lt;br /&gt; &lt;br /&gt;class DBCacheRecord {&lt;br /&gt;  Object data;&lt;br /&gt;  long time;&lt;br /&gt; &lt;br /&gt;  public DBCacheRecord(Object results, long when) {&lt;br /&gt;    time=when;&lt;br /&gt;    data=results;&lt;br /&gt;  }&lt;br /&gt;  public Object getResults() {&lt;br /&gt;	return data;&lt;br /&gt;  }&lt;br /&gt;  public long getLastModified() {&lt;br /&gt;	return time;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;public class DBCache {&lt;br /&gt;  Map cache;&lt;br /&gt; &lt;br /&gt;  public DBCache() {&lt;br /&gt;    cache = new HashMap();&lt;br /&gt;  }&lt;br /&gt; &lt;br /&gt;  public Object getDBData(String dbcommand) {&lt;br /&gt;    if(!cache.containsKey(dbcommand)) {&lt;br /&gt;	synchronized(cache) {	&lt;br /&gt;	  cache.put(dbcommand, readDBData(dbcommand)); &lt;br /&gt;        }&lt;br /&gt;     } else {&lt;br /&gt;       if((new Date().getTime() ) -&lt;br /&gt;         ((DBCacheRecord)cache.get(&lt;br /&gt;		dbcommand)).getLastModified()&amp;gt;=1000) {&lt;br /&gt;	 synchronized(cache) {	&lt;br /&gt;	   cache.put(dbcommand, readDBData(dbcommand)); &lt;br /&gt;         }&lt;br /&gt;       }	&lt;br /&gt;     }&lt;br /&gt;     return ((DBCacheRecord)cache.get(&lt;br /&gt;	dbcommand)).getResults();&lt;br /&gt;  }&lt;br /&gt; &lt;br /&gt;  public Object readDBData(String dbcommand) {&lt;br /&gt; &lt;br /&gt;/*Insert your JDBC code here For Example:&lt;br /&gt;  ResultSet results=stmt.executeQuery(dbcommand);&lt;br /&gt;*/&lt;br /&gt;    String results=&amp;quot;example results&amp;quot;;&lt;br /&gt;    return(new DBCacheRecord(results,new &lt;br /&gt;			     Date().getTime()));&lt;br /&gt;	&lt;br /&gt;  }&lt;br /&gt; &lt;br /&gt;  public static void main(String args[]) {&lt;br /&gt;    DBCache d1=new DBCache();&lt;br /&gt;    for(int i=1;i&amp;lt;=20;i++) {&lt;br /&gt;	d1.getDBData(&lt;br /&gt;	  &amp;quot;select count(*) from results where &lt;br /&gt;	  TO_DATE(results.completed) &amp;lt;=SYSDATE&amp;quot;);&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;                &lt;/td&gt;&lt;br /&gt;              &lt;/tr&gt;&lt;br /&gt;            &lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;          &lt;span class="sp20"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;          &lt;br /&gt;&lt;!-- END VCD7 CODE SAMPLE COMPONENT  --&gt;&lt;a name="more"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;          &lt;p&gt;&lt;b&gt;Caching Many Objects&lt;/b&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;          &lt;p&gt;Sometimes you will want to cache more than one object. For example, you might want to keep the most recently accessed files on a web server in a cache. If you use a &lt;code&gt;HashMap&lt;/code&gt; object for a purpose like this, it will continue to grow and use a lot of memory. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;          &lt;p&gt;If your machine has large amounts of memory and only a small number of objects to cache then a growing &lt;code&gt;HashMap&lt;/code&gt; may not be a problem. However, if you are intending to cache alot of objects then you may find that keeping only the most recent objects in the cache provides the best use of the machines memory. You can combine a &lt;code&gt;HashMap&lt;/code&gt; object with a &lt;code&gt;LinkedList&lt;/code&gt; to create what is called a Most Recently Used (MRU) cache. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;          &lt;p&gt;&lt;!-- BEGIN FRAGMENT | HR TAG --&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;          &lt;div class="contentdivider"&gt;&lt;br /&gt;            &lt;table class="grey4" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;br /&gt;                &lt;tr&gt;&lt;br /&gt;                  &lt;td&gt;&lt;img border="0" alt=" " src="/im/a.gif" width="1" height="4" /&gt;&lt;/td&gt;&lt;br /&gt;                &lt;/tr&gt;&lt;br /&gt;              &lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;          &lt;/div&gt;&lt;br /&gt;&lt;!-- END FRAGMENT | HR TAG --&gt;&lt;br /&gt;&lt;br /&gt;          &lt;blockquote&gt;&lt;strong&gt;Note:&lt;/strong&gt; There are other techniques used to constrain cache size besides MRU. MRU is one of the simpler algorithms. &lt;/blockquote&gt;&lt;br /&gt;&lt;!-- BEGIN FRAGMENT | HR TAG --&gt;&lt;br /&gt;&lt;br /&gt;          &lt;div class="contentdivider"&gt;&lt;br /&gt;            &lt;table class="grey4" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;br /&gt;                &lt;tr&gt;&lt;br /&gt;                  &lt;td&gt;&lt;img border="0" alt=" " src="/im/a.gif" width="1" height="4" /&gt;&lt;/td&gt;&lt;br /&gt;                &lt;/tr&gt;&lt;br /&gt;              &lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;          &lt;/div&gt;&lt;br /&gt;&lt;!-- END FRAGMENT | HR TAG --&gt;&lt;br /&gt;&lt;br /&gt;          &lt;p&gt;With an MRU cache, you can place a constraint on which objects remain in cache, and thereby, control the size of the cache. There are three main operations that the MRU cache has to perform: &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;          &lt;ul&gt;&lt;br /&gt;            &lt;li&gt;If the cache is not full, new objects not already in the cache are inserted at the head of the list. &lt;br /&gt;              &lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;              &lt;p&gt;&lt;/p&gt;&lt;br /&gt;            &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;            &lt;li&gt;If the cache is not full and the object to be inserted already exists in the cache, it is moved to the head of the list. &lt;br /&gt;              &lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;              &lt;p&gt;&lt;/p&gt;&lt;br /&gt;            &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;            &lt;li&gt;If the cache is full and a new object is to be inserted, the last object in the cache is removed and the new object is inserted at the head of the list. &lt;/li&gt;&lt;br /&gt;          &lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;          &lt;p&gt;This diagram shows how the &lt;code&gt;LinkedList&lt;/code&gt; and &lt;code&gt;HashMap&lt;/code&gt; work together to implement the operations described above. A discussion of the diagram follows. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;          &lt;p&gt;&lt;a href="http://lh3.ggpht.com/_iuwZHhydmEs/SlqTVsJW43I/AAAAAAAAA00/VbPZo7ENFC0/s1600-h/cach%5B2%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="cach" border="0" alt="cach" src="http://lh6.ggpht.com/_iuwZHhydmEs/SlqTZqIJpNI/AAAAAAAAA04/NleJ8WxjWf4/cach_thumb.png?imgmax=800" width="320" height="324" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;          &lt;div align="center"&gt;&lt;strong&gt;MRU Cache with LinkedList and HashMap&lt;/strong&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;          &lt;p&gt;The &lt;code&gt;LinkedList&lt;/code&gt; provides the queue mechanism, and the entries in the &lt;code&gt;LinkedList&lt;/code&gt; contain the key to the data in the &lt;code&gt;HashMap&lt;/code&gt;. To add a new entry to the front of the list, the &lt;code&gt;addFirst&lt;/code&gt; method is called. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;          &lt;ul&gt;&lt;br /&gt;            &lt;li&gt;If the list is already full, the &lt;code&gt;removeLast&lt;/code&gt; method is called and the data entry is also removed from the &lt;code&gt;HashMap&lt;/code&gt;. &lt;br /&gt;&lt;br /&gt;              &lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;              &lt;p&gt;&lt;/p&gt;&lt;br /&gt;            &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;            &lt;li&gt;If an entry was already in the list, it is removed with a call to the &lt;code&gt;remove&lt;/code&gt; method and inserted at the front of the list with a call to the &lt;code&gt;addFirst&lt;/code&gt; method. &lt;/li&gt;&lt;br /&gt;          &lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;          &lt;p&gt;The Collections API does not implement locking, so if you remove entries from or add entries to &lt;code&gt;LinkedList&lt;/code&gt; or &lt;code&gt;HashMap&lt;/code&gt; objects, you need to lock access to these objects. You can also use a &lt;code&gt;Vector&lt;/code&gt; or &lt;code&gt;ArrayList&lt;/code&gt; to get the same results as shown in the code below with the &lt;code&gt;LinkedList&lt;/code&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;          &lt;p&gt;This &lt;a href="/developer/onlineTraining/Programming/JDCBook/Code/MRUCache.java"&gt;code example&lt;/a&gt; uses an MRU cache to keep a cache of files loaded from disk. When a file is requested, the program checks to see if the file is in the cache. If the file is not in the cache, the program reads the file from disk and places the cache copy at the beginning of the list. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;          &lt;p&gt;If the file is in cache, the program compares the modification times of the file and cache entry. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;          &lt;ul&gt;&lt;br /&gt;            &lt;li&gt;If the cache entry time is older, the program reads the file from disk, removes the cache copy, and places a new copy in the cache at the front of the &lt;code&gt;LinkedList&lt;/code&gt;. &lt;br /&gt;&lt;br /&gt;              &lt;p&gt;&lt;/p&gt;&lt;br /&gt;            &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;            &lt;li&gt;If the file time is older, the program gets the file from the cache and moves the cache copy to the front of the list. &lt;/li&gt;&lt;br /&gt;          &lt;/ul&gt;&lt;br /&gt;&lt;!-- BEGIN VCD7 CODE SAMPLE COMPONENT  --&gt;&lt;br /&gt;&lt;br /&gt;          &lt;table class="grey4" border="0" cellspacing="0" cellpadding="10" width="100%"&gt;&lt;tbody&gt;&lt;br /&gt;              &lt;tr&gt;&lt;br /&gt;                &lt;td&gt;&lt;br /&gt;                  &lt;pre&gt; &lt;br /&gt;import java.util.*;&lt;br /&gt;import java.io.*;&lt;br /&gt; &lt;br /&gt;class myFile {&lt;br /&gt;  long lastmodified;&lt;br /&gt;  String contents;&lt;br /&gt; &lt;br /&gt;  public myFile(long last, String data) {&lt;br /&gt;    lastmodified=last;&lt;br /&gt;    contents=data;		&lt;br /&gt;  }&lt;br /&gt;  public long getLastModified() {&lt;br /&gt;    return lastmodified;&lt;br /&gt;  }&lt;br /&gt;  public String getContents() {&lt;br /&gt;    return contents;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;public class MRUCache {&lt;br /&gt; &lt;br /&gt;  Map cache;&lt;br /&gt;  LinkedList mrulist;&lt;br /&gt;  int cachesize;&lt;br /&gt; &lt;br /&gt;  public MRUCache(int max) {&lt;br /&gt;    cache = new HashMap();&lt;br /&gt;    mrulist= new LinkedList();&lt;br /&gt;    cachesize=max;&lt;br /&gt;  }&lt;br /&gt; &lt;br /&gt;  public String getFile(String fname) {&lt;br /&gt;    if(!cache.containsKey(fname)) {&lt;br /&gt;      synchronized(cache) {	&lt;br /&gt;        if(mrulist.size() &amp;gt;=cachesize) {&lt;br /&gt;	  cache.remove(mrulist.getLast());&lt;br /&gt;	  mrulist.removeLast();&lt;br /&gt;        }&lt;br /&gt;        cache.put(fname, readFile(fname)); &lt;br /&gt;        mrulist.addFirst(fname);&lt;br /&gt;      }&lt;br /&gt;    } else {&lt;br /&gt;      if((new File(fname).lastModified())&amp;gt; &lt;br /&gt;	((myFile)cache.get(fname)).getLastModified()) {&lt;br /&gt;	  synchronized(cache) {	&lt;br /&gt;	    cache.put(fname, readFile(fname)); &lt;br /&gt;          }&lt;br /&gt;       }	&lt;br /&gt;       synchronized(cache) {&lt;br /&gt;	 mrulist.remove(fname);&lt;br /&gt;	 mrulist.addFirst(fname);&lt;br /&gt;       }&lt;br /&gt;    }&lt;br /&gt;       return ((myFile)cache.get(fname)).getContents();&lt;br /&gt;  }&lt;br /&gt;	&lt;br /&gt;  public myFile readFile(String name) {&lt;br /&gt;    File f = new File(name);&lt;br /&gt;    StringBuffer filecontents= new StringBuffer();&lt;br /&gt; &lt;br /&gt;    try {&lt;br /&gt;      BufferedReader br=new BufferedReader(&lt;br /&gt;                              new FileReader(f));&lt;br /&gt;      String line;&lt;br /&gt; &lt;br /&gt;      while((line =br.readLine()) != null) {&lt;br /&gt;	filecontents.append(line);&lt;br /&gt;      }	&lt;br /&gt;    } catch (FileNotFoundException fnfe){&lt;br /&gt;      return (null);&lt;br /&gt;    } catch ( IOException ioe) {&lt;br /&gt;		return (null);&lt;br /&gt;    }&lt;br /&gt;      return (new myFile(f.lastModified(), &lt;br /&gt;		filecontents.toString()));&lt;br /&gt;  }&lt;br /&gt; &lt;br /&gt;  public void printList() {&lt;br /&gt;    for(int i=0;i&amp;lt;mrulist.size();i++) {&lt;br /&gt;      System.out.println(&amp;quot;item &amp;quot;+i+&amp;quot;=&amp;quot;+mrulist.get(i));&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt; &lt;br /&gt;  public static void main(String args[]) {&lt;br /&gt; &lt;br /&gt;    // Number of entries in MRU cache is set to 10 &lt;br /&gt;    MRUCache h1=new MRUCache(10);&lt;br /&gt;    for(int i=1;i&amp;lt;=20;i++) {&lt;br /&gt;      // files are stored in a subdirectory called data&lt;br /&gt;      h1.getFile(&amp;quot;data&amp;quot;+File.separatorChar+i);&lt;br /&gt;    }&lt;br /&gt;      h1.printList();&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;                &lt;/td&gt;&lt;br /&gt;              &lt;/tr&gt;&lt;br /&gt;            &lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;          &lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;!-- ================ --&gt;&lt;!-- End Main Content --&gt;&lt;!-- ================ --&gt;&lt;!-- =================== --&gt;&lt;!-- END OF MAIN CONTENT --&gt;&lt;!-- =================== --&gt;&lt;!--stopindex--&gt;&lt;!-- END CENTRAL COLUMN COMPONENTS --&gt;&lt;/td&gt;&lt;br /&gt;&lt;br /&gt;        &lt;td valign="top"&gt;&lt;!-- BEGIN RIGHT COLUMN COMPONENTS --&gt;&lt;!-- END RIGHT COLUMN COMPONENTS --&gt;&lt;/td&gt;&lt;br /&gt;      &lt;/tr&gt;&lt;br /&gt;&lt;!-- BEGIN SPACER ROW --&gt;&lt;br /&gt;&lt;br /&gt;      &lt;tr&gt;&lt;br /&gt;        &lt;td&gt;&amp;#160;&lt;/td&gt;&lt;br /&gt;&lt;br /&gt;        &lt;td&gt;&amp;#160;&lt;/td&gt;&lt;br /&gt;      &lt;/tr&gt;&lt;br /&gt;&lt;!-- END SPACER ROW --&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;!-- END WRAPPER TABLE, 2 COLUMN, MAIN/RIGHT --&gt;&lt;!-- BEGIN G9 VARIATION 0 --&gt;&lt;script language="javascript" type="text/javascript" charset="UTF-8" src="/js/op/oo_engine.js"&gt;&lt;/script&gt;&lt;script language="javascript" type="text/javascript" charset="UTF-8" src="/js/op/oo_conf_en-US.js"&gt;&lt;/script&gt;&lt;!-- END G9 VARIATION 0 --&gt;&lt;!-- BEGIN VNV5 FOOTER  --&gt;&lt;br /&gt;&lt;br /&gt;  &lt;table border="0" cellspacing="10" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;br /&gt;      &lt;tr&gt;&lt;br /&gt;        &lt;td&gt;&lt;br /&gt;          &lt;table class="vatop" border="0" cellspacing="0" cellpadding="0" width="100%"&gt;&lt;tbody&gt;&lt;br /&gt;              &lt;tr&gt;&lt;br /&gt;                &lt;td class="grey3" valign="top" colspan="4"&gt;&lt;/td&gt;&lt;br /&gt;              &lt;/tr&gt;&lt;br /&gt;&lt;br /&gt;              &lt;tr&gt;&lt;br /&gt;                &lt;td&gt;&lt;br /&gt;                  &lt;br /&gt;Source: &lt;a href="http://java.sun.com/developer/onlineTraining/Programming/JDCBook/perf4.html"&gt;http://java.sun.com/developer/onlineTraining/Programming/JDCBook/perf4.html&lt;/a&gt;&lt;/td&gt;&lt;br /&gt;&lt;br /&gt;                &lt;td valign="top" width="100%"&gt;&lt;br /&gt;                  &lt;div class="footer"&gt;&amp;#160;&lt;/div&gt;&lt;br /&gt;                &lt;/td&gt;&lt;br /&gt;&lt;br /&gt;                &lt;td&gt;&lt;/td&gt;&lt;br /&gt;&lt;br /&gt;                &lt;td valign="top"&gt;&lt;br /&gt;                  &lt;div class="footer"&gt;&lt;br /&gt;                    &lt;br /&gt;&lt;span class="sp5"&gt;&amp;#160;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;                    &lt;br /&gt;&amp;#160;&lt;/div&gt;&lt;br /&gt;                &lt;/td&gt;&lt;br /&gt;              &lt;/tr&gt;&lt;br /&gt;&lt;br /&gt;              &lt;tr&gt;&lt;br /&gt;                &lt;td class="grey3" valign="top" colspan="4"&gt;&lt;/td&gt;&lt;br /&gt;              &lt;/tr&gt;&lt;br /&gt;            &lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;        &lt;/td&gt;&lt;br /&gt;      &lt;/tr&gt;&lt;br /&gt;    &lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;!-- END VNV5 FOOTER --&gt;&lt;script language="JavaScript" src="/js/omi/jsc/s_code_remote.js"&gt;&lt;/script&gt;&lt;/div&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-542832273974411059?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/542832273974411059/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2009/07/chapter-8-continued-caching.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/542832273974411059'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/542832273974411059'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2009/07/chapter-8-continued-caching.html' title='Chapter 8 Continued: Caching Client/Server Applications'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_iuwZHhydmEs/SlqTZqIJpNI/AAAAAAAAA04/NleJ8WxjWf4/s72-c/cach_thumb.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-2629736609569480046</id><published>2009-07-02T02:58:00.001-07:00</published><updated>2009-07-02T02:58:41.519-07:00</updated><title type='text'>Comparing Web Site Projects and Web Application Projects</title><content type='html'>&lt;p&gt;Introduction to Web Application Projects&lt;/p&gt;  &lt;p&gt;Microsoft Corporation&lt;/p&gt;  &lt;p&gt;April 2006&lt;/p&gt;  &lt;p&gt;Applies to:   &lt;br /&gt;&amp;#160;&amp;#160; Visual Studio 2005    &lt;br /&gt;&amp;#160;&amp;#160; Visual Studio .NET 2003&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Summary:&lt;/b&gt; Find out how to use the new project type, the Web application project, as an alternative to the Web site project model already available in Visual Studio 2005. (27 printed pages)&lt;/p&gt;  &lt;h6&gt;Contents&lt;/h6&gt;  &lt;p&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic1"&gt;Introduction&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic2"&gt;Purpose of Web Application Projects&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic3"&gt;In This Paper&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic4"&gt;Installing Web Application Projects&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic5"&gt;Comparing Web Site Projects and Web Application Projects&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic6"&gt;Scenario 1: Creating a New Web Application Project&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic7"&gt;Step 1: Create a New Project&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic8"&gt;Step 2: Open and Edit the Page&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic9"&gt;Step 3: Build and Run the Project&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic10"&gt;Setting Build and Deployment Properties for Web Application Projects&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic11"&gt;Customizing Deployment Options for Web Application Projects&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic12"&gt;Scenario 2: Migrating a Visual Studio .NET 2003 Web Project to a Web Application Project&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic13"&gt;Step 1: Install the Visual Studio 2005 Web Application Project Preview&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic14"&gt;Step 2: Back Up Your Visual Studio .NET 2003 Projects&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic15"&gt;Step 3: Open and Verify your Visual Studio .NET 2003 Web Project&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic16"&gt;Step 4: Migrate the Solution to Visual Studio 2005&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic17"&gt;Step 5: Verify in Visual Studio 2005&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic18"&gt;Step 6: Covert Code-Behind Classes to Partial Classes&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic19"&gt;Step 7: Examine and Resolve XHTML Compliance Issues&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic20"&gt;The Future of Web Application Projects&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic21"&gt;Appendix A: Known Issues&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic22"&gt;Issue 1: Data Scenarios&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic23"&gt;Issue 2: Visual Basic Inline Code Might Not Be Converted Correctly&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic24"&gt;Issue 3: WSE and Web Application Projects&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic25"&gt;Issue 4: Converting the Club Web Site Starter Kit (Visual Basic)&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic26"&gt;Issue 5: Converting the Personal Web Site Starter Kit (Visual Basic)&lt;/a&gt;    &lt;br /&gt;&lt;a href="http://msdn.microsoft.com/#wapp_topic27"&gt;Issue 6: Converting a Visual Studio 2005 Web Site project to a Web Application Project&lt;/a&gt;&lt;/p&gt;  &lt;h4&gt;&lt;a name="wapp_topic1"&gt;&lt;/a&gt;Introduction&lt;/h4&gt;  &lt;p&gt;The Web Application Projects add-in provides a Visual Studio 2005 Web project model option that works like the Visual Studio .NET 2003 Web project model. In this paper, the new project type is referred to as a Web application project. You can use Web application projects as an alternative to the Web site project model already available in Visual Studio 2005, which we refer to in this paper as Web site projects.&lt;/p&gt;  &lt;h5&gt;&lt;a name="wapp_topic2"&gt;&lt;/a&gt;Purpose of Web Application Projects&lt;/h5&gt;  &lt;p&gt;The goal of Web application projects is to address some of the feedback we have heard from customers. Some developers find migrating Visual Studio .NET 2003 applications to the new Web site model in Visual Studio 2005 impractical, especially because precompiling (publishing) a Visual Studio 2005 Web site creates multiple assemblies.&lt;/p&gt;  &lt;p&gt;The new Web application project type also enables some scenarios where Visual Studio 2005 Web projects are different than in the previous version of Visual Studio. For example, the new model has different semantics for Web subprojects where the subproject is not an ASP.NET or IIS application, but instead feeds its generated assembly to a parent application's Bin folder.&lt;/p&gt;  &lt;p&gt;The new project type also provides a model that will feel familiar to developers who do not want to change how they structure their Web projects from how they use Visual Studio .NET 2003 today—for example, they want to continue to use a project file.&lt;/p&gt;  &lt;p&gt;The new Web application project type does not replace the Web site project type introduced in Visual Studio 2005, which provides many new features and additional flexibility in how you manage Web applications. Instead, it is an alternative project type that you might choose depending on your requirements and your preferred development workflow. Some developers will find the default Visual Studio 2005 Web site project model natural and easy to use. Other developers will prefer a model in which project resources are defined explicitly (rather than implicitly by simply being in a folder) and in which they have tighter control over their project, and will therefore choose the new Web application project model. Rather than forcing developers to use just one project model, we will support both project models and allow developers to choose whichever Web project model works best for them.&lt;/p&gt;  &lt;blockquote&gt;&lt;b&gt;Note&lt;/b&gt;&amp;#160;&amp;#160; Web application projects do not work with Visual Web Developer Express Edition.&lt;/blockquote&gt;  &lt;h5&gt;&lt;a name="wapp_topic3"&gt;&lt;/a&gt;In This Paper&lt;/h5&gt;  &lt;p&gt;This paper describes Web application projects and offers information on when you might choose between a Web application project and a Web site project model in Visual Studio 2005. The paper also walks you through the following common scenarios:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Creating a new Web application project in Visual Studio 2005. &lt;/li&gt;    &lt;li&gt;Migrating an existing Visual Studio .NET 2003 project to a Visual Studio 2005 Web application project.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In addition, an appendix lists known issues with Web application projects.&lt;/p&gt;  &lt;h4&gt;&lt;a name="wapp_topic4"&gt;&lt;/a&gt;Installing Web Application Projects&lt;/h4&gt;  &lt;p&gt;Adding Web application projects to Visual Studio 2005 requires you to install both an update and an add-in to Visual Studio 2005. The two installations perform the following tasks:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The update makes changes to Visual Studio 2005 that are required so the Web project conversion wizard and designer will work well with Web application projects. You can download the update from the &lt;a href="http://go.microsoft.com/fwlink/?LinkId=63636"&gt;Microsoft Visual Studio 2005 - Update to Support Web Application Projects&lt;/a&gt; [ http://go.microsoft.com/fwlink/?LinkId=63636 ] page on the Microsoft Download Center Web site. &lt;/li&gt;    &lt;li&gt;The add-in makes the new Web application projects available in Visual Studio 2005. You can download it from the &lt;a href="http://go.microsoft.com/fwlink/?LinkId=57541"&gt;Visual Studio 2005 Web Application Projects&lt;/a&gt; [ http://go.microsoft.com/fwlink/?LinkId=57541 ] page on the ASP.NET Developer Center.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Early versions of Web application projects (V1 and V2 previews) were released in December 2005 and February 2006. The most recent version adds support for generating code to represent server controls and for converting projects directly from Visual Studio .NET 2003 to Web application projects in Visual Studio 2005.&lt;/p&gt;  &lt;h4&gt;&lt;a name="wapp_topic5"&gt;&lt;/a&gt;Comparing Web Site Projects and Web Application Projects&lt;/h4&gt;  &lt;p&gt;The new Web application project model provides the same Web project semantics as Visual Studio .NET 2003 Web projects. This includes a structure based on project files and a build model where all code in the project is compiled into a single assembly. However, the new project type makes available all the new features of Visual Studio 2005 (refactoring, class diagrams, test development, generics, and so on) and of ASP.NET 2.0 (master pages, data controls, membership and login, role management, Web Parts, personalization, site navigation, themes, and so on).&lt;/p&gt;  &lt;p&gt;The Web application project model in Visual Studio 2005 also removes two requirements from Visual Studio .NET 2003:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Using FrontPage Server Extensions (FPSE). These are no longer required, but they are supported if your site already uses them. &lt;/li&gt;    &lt;li&gt;Using a local copy of IIS. The new project type supports both IIS and the built-in ASP.NET Development Server.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The following two tables describe the differences between Web application projects and Web site projects. The first table highlights various scenarios and tasks and suggests which model is best suited to that task. The second table describes in more detail the behavioral differences between each model. Use the tables to guide you in selecting which model to select.&lt;/p&gt;  &lt;p&gt;The following table lists Web project options or tasks and indicates which project model best implements those options.&lt;/p&gt;  &lt;p&gt;Option or Task   &lt;br /&gt;Web Application Projects    &lt;br /&gt;Web Site Projects&lt;/p&gt;  &lt;p&gt;Need to migrate large Visual Studio .NET 2003 applications   &lt;br /&gt;X&lt;/p&gt;  &lt;p&gt;Prefer single-page code model to code-behind model   &lt;br /&gt;X&lt;/p&gt;  &lt;p&gt;Prefer dynamic compilation and working on pages without building entire site on each page view (that is, save file and then simply refresh the page in the browser).   &lt;br /&gt;X&lt;/p&gt;  &lt;p&gt;Need to control names of output assemblies   &lt;br /&gt;X&lt;/p&gt;  &lt;p&gt;Need to generate one assembly for each page   &lt;br /&gt;X&lt;/p&gt;  &lt;p&gt;Need stand-alone classes to reference page and user control classes   &lt;br /&gt;X&lt;/p&gt;  &lt;p&gt;Need to build a Web application using multiple Web projects   &lt;br /&gt;X&lt;/p&gt;  &lt;p&gt;Need to add pre-build and post-build steps during compilation   &lt;br /&gt;X&lt;/p&gt;  &lt;p&gt;Want to open and edit any directory as a Web project without creating a project file   &lt;br /&gt;X&lt;/p&gt;  &lt;p&gt;The following table helps you select a project type by describing some of the key differences between Web application projects and Web site projects.&lt;/p&gt;  &lt;p&gt;Scenario   &lt;br /&gt;Web Application Project    &lt;br /&gt;Web Site Project&lt;/p&gt;  &lt;p&gt;Project definition   &lt;br /&gt;Similar to Visual Studio .NET 2003. Only files that are referenced in the project file are part of the project, are displayed in Solution Explorer, and are compiled during a build. Because there is a project file, some scenarios are more easily enabled: &lt;/p&gt;  &lt;p&gt;You can subdivide one ASP.NET application into multiple Visual Studio projects.&lt;/p&gt;  &lt;p&gt;You can easily exclude files from the project and from source code-control.&lt;/p&gt;  &lt;p&gt;Web site projects use the folder structure to define the contents of the project. There is no project file and all files in the folder are part of the project. &lt;/p&gt;  &lt;p&gt;This project type is desirable if you have an existing folder structure representing an ASP.NET application that you want to edit in Visual Studio without having to explicitly create a project file.&lt;/p&gt;  &lt;p&gt;Compilation and build outputs   &lt;br /&gt;The compilation model for Web application projects is very similar to that in Visual Studio .NET 2003. &lt;/p&gt;  &lt;p&gt;All code-behind class files and stand-alone class files in the project are compiled into a single assembly, which is placed in the Bin folder. Because this is a single assembly, you can specify attributes such as assembly name and version, as well as the location of the output assembly.&lt;/p&gt;  &lt;p&gt;Certain other applications scenarios are better enabled, such as the Model-View-Controller (MVC) pattern, because they allow stand-alone classes in the project to reference page and user control classes.&lt;/p&gt;  &lt;p&gt;The &lt;b&gt;Build&lt;/b&gt;command compiles Web site projects only to test them. To run Web site projects, you deploy source files and rely on ASP.NET dynamic compilation to compile pages and classes in the application. &lt;/p&gt;  &lt;p&gt;Alternatively, you can precompile the site for performance, which uses the same compilation semantics as ASP.NET dynamic compilation. The ASP.NET dynamic compilation system has two modes—batch mode (the default) and fixed-names mode. In batch mode, many assemblies (typically one per folder) are produced when precompiling the site. In fixed mode, one assembly is produced for each page or user control in the Web site.&lt;/p&gt;  &lt;p&gt;Iterative development   &lt;br /&gt;To run and debug pages, you must build the entire Web project. Building the entire Web application project is usually fast, because Visual Studio employs an incremental build model that builds only the files that have changed.    &lt;br /&gt;You can configure build options Visual Studio 2005 for when you run the site: build the site, an individual page, or nothing at all. In the last case, when you run a Web site, Visual Studio simply launches the browser and passes to it the current or start page. The request then invokes ASP.NET dynamic compilation. &lt;/p&gt;  &lt;p&gt;Because pages are compiled dynamically and compiled into different assemblies as needed, it is not required that the entire project compile successfully in order to run and debug a page.&lt;/p&gt;  &lt;p&gt;By default, Visual Studio completely compiles Web site projects whenever you run or debug any page. This is done to identify compile-time errors anywhere in the site. However, a complete site build can significantly slow down the iterative development process, so it is generally recommended that you change the build project option to compile only the current page on run or debug.&lt;/p&gt;  &lt;p&gt;Deployment   &lt;br /&gt;Because all class files are compiled into a single assembly, only that assembly needs to be deployed, along with the .aspx and .ascx files and other static content files. &lt;/p&gt;  &lt;p&gt;In this model, .aspx files are not compiled until they are run in the browser. However, when used with Web Deployment Projects (a downloadable add-in to Visual Studio 2005), the .aspx files can also be compiled and included in a single assembly for deployment.&lt;/p&gt;  &lt;p&gt;Each time you deploy the single assembly produced in this model, you replace the code for all pages in the project.&lt;/p&gt;  &lt;p&gt;Both .aspx files and code-behind files can be compiled into assemblies using the&lt;b&gt;Publish Website&lt;/b&gt;command in Visual Studio. (Note that the&lt;b&gt;Build&lt;/b&gt; command does not create a deployable set of assemblies.) The updateable publish option supports compiling only code-behind files while leaving .aspx files unchanged for deployment. &lt;/p&gt;  &lt;p&gt;The default mode for precompiling produces several assemblies in the Bin folder, typically one per folder. The fixed-names option produces one assembly per page or user control and can be used to create deployable versions of individual pages. However, the fixed-names option increases the number of assemblies and can result in increased memory usage.&lt;/p&gt;  &lt;p&gt;Upgrade from Visual Studio .NET 2003   &lt;br /&gt;Because the Web application project model is the same as in the Visual Studio .NET 2003, upgrade is generally simple and will usually not require any restructuring of the application.    &lt;br /&gt;The compilation option for Web site projects is significantly different than Visual Studio .NET 2003. A conversion wizard is available to upgrade existing Visual Studio .NET 2003 Web projects to Web site projects. For any reasonably complex Visual Studio .NET 2003 projects, manual fix-up is usually required after the conversion. For most scenarios, it is preferable to upgrade existing Visual Studio .NET 2003 projects to Web application projects in Visual Studio 2005.&lt;/p&gt;  &lt;h4&gt;&lt;a name="wapp_topic6"&gt;&lt;/a&gt;Scenario 1: Creating a New Web Application Project&lt;/h4&gt;  &lt;p&gt;This section walks you through creating a new Web application project. It also examines how page code is handled in a Visual Studio 2005 Web application project.&lt;/p&gt;  &lt;blockquote&gt;&lt;b&gt;Note&lt;/b&gt;&amp;#160;&amp;#160; Web application projects do not work with Visual Web Developer Express Edition.&lt;/blockquote&gt;  &lt;p&gt;The examples shown here are in C#. The steps for working with Visual Basic are very similar, but file names and code will differ slightly.&lt;/p&gt;  &lt;h5&gt;&lt;a name="wapp_topic7"&gt;&lt;/a&gt;Step 1: Create a New Project&lt;/h5&gt;  &lt;p&gt;To start, create a new Web application project. In Visual Studio, from the &lt;b&gt;File&lt;/b&gt; menu, click &lt;b&gt;New Project&lt;/b&gt;, displays the &lt;b&gt;New Project&lt;/b&gt; dialog box.&lt;/p&gt;  &lt;blockquote&gt;&lt;b&gt;Note&lt;/b&gt;&amp;#160;&amp;#160; To create a Web application project, you do not choose the &lt;b&gt;New Web Site&lt;/b&gt; command, as you do to create a Web site project. Instead, you choose the &lt;b&gt;New Project&lt;/b&gt; command.&lt;/blockquote&gt;  &lt;p&gt;Under &lt;b&gt;Project types&lt;/b&gt;, open the &lt;b&gt;Visual C#&lt;/b&gt; or &lt;b&gt;Visual Basic&lt;/b&gt; node, and then under &lt;b&gt;Visual Studio installed templates&lt;/b&gt;, click &lt;b&gt;ASP.NET Web Application&lt;/b&gt;:&lt;/p&gt;  &lt;p&gt;&lt;img border="0" alt="" src="http://i.msdn.microsoft.com/Aa730880.wap_01(en-US,VS.80).gif" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Figure 1. Creating a new Web Application Project&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Name the project and specify a location. When you click &lt;b&gt;OK&lt;/b&gt;, Visual Studio creates and opens a new Web project with a single page named Default.aspx, an AssemblyInfo.cs file (.vb file), and a Web.config file:&lt;/p&gt;  &lt;p&gt;&lt;img border="0" alt="" src="http://i.msdn.microsoft.com/Aa730880.wap_02(en-US,VS.80).gif" /&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Figure 2. New Web application project&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;This list of project files, references, compilation information, and other metadata is stored in the project file, which is created in whatever location you specify in the &lt;b&gt;New Project&lt;/b&gt; dialog box.&lt;/p&gt;  &lt;p&gt;There are two class files (.cs files or .vb files) associated with the Default.aspx page. The Default.cs file (.vb file) contains the page class where you put your code and event handlers. The Default.aspx.designer.cs file (.vb file) is a new file used in Web application projects to contain the code that is generated and maintained by Visual Studio for the page. Both files contain a partial class. During compilation, the files are combined into a single code-behind class.&lt;/p&gt;  &lt;h5&gt;&lt;a name="wapp_topic8"&gt;&lt;/a&gt;Step 2: Open and Edit the Page&lt;/h5&gt;  &lt;p&gt;Open the Default.aspx file and copy the following markup into it, which defines several ASP.NET server controls:&lt;/p&gt;  &lt;pre&gt;&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; AutoEventWireup=&amp;quot;true&amp;quot; CodeBehind=&amp;quot;Default.aspx.cs&amp;quot; Inherits=&amp;quot;WebApplication3._Default&amp;quot; %&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;title&amp;gt;My Visual Studio 2005 Web Application Project Test&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;  &amp;lt;form id=&amp;quot;form1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;div&amp;gt;&lt;br /&gt;    &lt;br /&gt;        &amp;lt;h1&amp;gt;My Visual Studio 2005 Web Application Project Test&amp;lt;/h1&amp;gt;&lt;br /&gt;        &amp;lt;h3&amp;gt;Pick a date: &amp;lt;/h3&amp;gt;&lt;br /&gt;        &amp;lt;asp:Calendar ID=&amp;quot;Calendar1&amp;quot; runat=&amp;quot;server&amp;quot; &lt;br /&gt;             BorderColor=&amp;quot;#999999&amp;quot; DayNameFormat=&amp;quot;Shortest&amp;quot; &lt;br /&gt;             Font-Names=&amp;quot;Verdana&amp;quot;&amp;gt;&lt;br /&gt;          &amp;lt;SelectedDayStyle BackColor=&amp;quot;#666666&amp;quot; &lt;br /&gt;             Font-Bold=&amp;quot;True&amp;quot; ForeColor=&amp;quot;White&amp;quot; /&amp;gt;&lt;br /&gt;          &amp;lt;TodayDayStyle BackColor=&amp;quot;#CCCCCC&amp;quot; ForeColor=&amp;quot;Black&amp;quot; /&amp;gt;&lt;br /&gt;          &amp;lt;SelectorStyle BackColor=&amp;quot;#CCCCCC&amp;quot; /&amp;gt;&lt;br /&gt;          &amp;lt;WeekendDayStyle BackColor=&amp;quot;#FFFFCC&amp;quot; /&amp;gt;&lt;br /&gt;          &amp;lt;OtherMonthDayStyle ForeColor=&amp;quot;#808080&amp;quot; /&amp;gt;&lt;br /&gt;          &amp;lt;NextPrevStyle VerticalAlign=&amp;quot;Bottom&amp;quot; /&amp;gt;&lt;br /&gt;          &amp;lt;DayHeaderStyle BackColor=&amp;quot;#CCCCCC&amp;quot; Font-Bold=&amp;quot;True&amp;quot; &lt;br /&gt;             Font-Size=&amp;quot;7pt&amp;quot; /&amp;gt;&lt;br /&gt;           &amp;lt;TitleStyle BackColor=&amp;quot;#999999&amp;quot; BorderColor=&amp;quot;Black&amp;quot; &lt;br /&gt;             Font-Bold=&amp;quot;True&amp;quot; /&amp;gt;&lt;br /&gt;        &amp;lt;/asp:Calendar&amp;gt;&lt;br /&gt;        &amp;lt;br /&amp;gt;&lt;br /&gt;        &amp;lt;div&amp;gt;&lt;br /&gt;          &amp;lt;asp:Label ID=&amp;quot;Label1&amp;quot; runat=&amp;quot;server&amp;quot; Text=&amp;quot;Label&amp;quot;/&amp;gt;&lt;br /&gt;        &amp;lt;/div&amp;gt;&lt;br /&gt;    &amp;lt;/div&amp;gt;&lt;br /&gt;  &amp;lt;/form&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In a Web application project, the Default.aspx.designer.cs file is automatically updated when you add or remove controls in the Default.aspx file. The following snippet shows what the Default.aspx.designer.cs file looks like after you add the preceding markup:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;namespace WebApplication3 &lt;br /&gt;{&lt;br /&gt;    public partial class _Default &lt;br /&gt;    {&lt;br /&gt;        protected System.Web.UI.HtmlControls.HtmlForm form1;&lt;br /&gt;        protected System.Web.UI.WebControls.Calendar Calendar1;&lt;br /&gt;        protected System.Web.UI.WebControls.Label Label1;&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;The Default.aspx.designer.cs file contains a control declaration for each server control in the .aspx (or .ascx) file. By default, the controls are declared as &lt;b&gt;protected&lt;/b&gt;. You can open the .designer.cs file and change a field's accessor to &lt;b&gt;public&lt;/b&gt; if you want to access the variable from outside of its class.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;b&gt;Note&lt;/b&gt;&amp;#160;&amp;#160; It is not recommended that you set the accessibility of control declarations to &lt;b&gt;public&lt;/b&gt;, because it is a better to use a property to change the accessibility of a server control variable. However, editing the access modifier for server variables in the designer file is supported for backward compatibility with Visual Studio .NET 2003 Web projects that used this coding technique.&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;In Web application projects, code generation for server controls is improved over the Visual Studio .NET 2003 experience in two important ways:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;You no longer have to switch the page to Design view to update the control declarations. The designer monitors both Design view and Source view and updates declarations appropriately. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;Control declarations in the base class of a page are honored and are not duplicated in a page's code-behind class.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Because the .designer.cs file is automatically updated with the control declarations, you can go directly to the Default.aspx.cs code-behind class file and program any of the controls on the page, as in the following example:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;using System;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Configuration;&lt;br /&gt;using System.Collections;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.Security;&lt;br /&gt;using System.Web.UI;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;using System.Web.UI.WebControls.WebParts;&lt;br /&gt;using System.Web.UI.HtmlControls;&lt;br /&gt;&lt;br /&gt;namespace WebApplication3 {&lt;br /&gt;&lt;br /&gt;    public partial class _Default : System.Web.UI.Page {&lt;br /&gt;&lt;br /&gt;        protected void Page_Load(object sender, EventArgs e) {&lt;br /&gt;&lt;tt&gt;&lt;b&gt;            Label1.Text = &amp;quot;Current date: &amp;quot; + Calendar1.SelectedDate;&lt;/b&gt;&lt;/tt&gt;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;&lt;a name="wapp_topic9"&gt;&lt;/a&gt;Step 3: Build and Run the Project&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Run the project in debug mode by pressing &lt;b&gt;F5&lt;/b&gt; or clicking &lt;b&gt;Run&lt;/b&gt; in the &lt;b&gt;Debug&lt;/b&gt; menu. By default, Web application projects use the built-in ASP.NET Development Server using a random port as the root site (for example, the site's URL might be &lt;tt&gt;http://localhost:12345/&lt;/tt&gt;):&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img border="0" alt="" src="http://i.msdn.microsoft.com/Aa730880.wap_03(en-US,VS.80).gif" /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Figure 3. Running a Web application project&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;When you build Web application projects, all code-behind classes, stand-alone class files, and embedded resources are compiled into a single assembly that is placed in the project's Bin folder.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;You can change the output location if you want to—for example, to build the project into a parent application directory. Typically, you set the build location when you have multiple subprojects in subfolders of a single ASP.NET application. Select the properties of the project to set the build location, as shown in the following screenshot:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img border="0" alt="" src="http://i.msdn.microsoft.com/Aa730880.wap_04(en-US,VS.80).gif" /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Figure 4. Setting output build location&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;After building the project, you can examine the results. In Solution Explorer, click &lt;b&gt;Show All Files&lt;/b&gt;:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img border="0" alt="" src="http://i.msdn.microsoft.com/Aa730880.wap_05(en-US,VS.80).gif" /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Figure 5. Results of building a Web application project&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This works the same as it does in Visual Studio .NET 2003 ASP.NET Web projects.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;&lt;a name="wapp_topic10"&gt;&lt;/a&gt;Setting Build and Deployment Properties for Web Application Projects&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;ASP.NET Web application projects use the same configuration settings and behaviors as Visual Studio 2005 class-library projects. You can access these configuration settings by right-clicking the project name in Solution Explorer and selecting &lt;b&gt;Properties&lt;/b&gt;. This displays the project properties editor. You can use the editor to change properties such as the name of the generated assembly, the build compilation settings for the project, its references, its resource string values, and code-signing settings:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img border="0" alt="" src="http://i.msdn.microsoft.com/Aa730880.wap_06(en-US,VS.80).gif" /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Figure 6. Changing properties of a Web application project&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;ASP.NET Web application projects add a tab named &lt;b&gt;Web&lt;/b&gt; to the project properties list. You can use this tab to configure how a Web project is run and debugged. By default, ASP.NET Web application projects are configured to launch and run using the built-in ASP.NET Development Server on a random HTTP port on the machine. The following screenshots show using the ASP.NET Development Server: the Taskbar icon, and a page in the browser where you can see the server's URL in the &lt;b&gt;Address&lt;/b&gt; box.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img border="0" alt="" src="http://i.msdn.microsoft.com/Aa730880.wap_07(en-US,VS.80).gif" /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Figure 7. Taskbar icon for ASP.NET Development Server&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img border="0" alt="" src="http://i.msdn.microsoft.com/Aa730880.wap_08(en-US,VS.80).gif" /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Figure 8. Running a Web application project using the ASP.NET Development Server&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;You can change the port number if the selected port is already in use or if you want to run the Web project on a specific port:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img border="0" alt="" src="http://i.msdn.microsoft.com/Aa730880.wap_09(en-US,VS.80).gif" /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Figure 9. Changing the port used by the ASP.NET Development Server&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Alternatively, Visual Studio can run and debug the Web application using IIS. To use IIS, select &lt;b&gt;Use IIS Web Server&lt;/b&gt; and enter the URL of the Web application:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img border="0" alt="" src="http://i.msdn.microsoft.com/Aa730880.wap_10(en-US,VS.80).gif" /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Figure 10. Configuring a Web application project to use IIS&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;b&gt;Note&lt;/b&gt;&amp;#160;&amp;#160; ASP.NET Web application projects do not automatically create an IIS virtual root or application for you. To create the virtual directory and application in IIS, click the &lt;b&gt;Create Virtual Directory&lt;/b&gt; button next to the &lt;b&gt;Url&lt;/b&gt; box.&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;When you run the application, Visual Studio compiles the project into a single assembly, which follows the build semantics of Visual Studio .NET 2003 Web projects. When the application is running, Visual Studio attaches a debugger to the Web server process.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;All project settings are saved in a standard MSBuild project file.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;&lt;a name="wapp_topic11"&gt;&lt;/a&gt;Customizing Deployment Options for Web Application Projects&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;After creating a Web application project, you can optionally use a Visual Studio 2005 Web Deployment project to set deployment options for the Web application project.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;b&gt;Note&lt;/b&gt;&amp;#160;&amp;#160; Web Deployment Projects is available as a Visual Studio 2005 add-in. You can download the add-in from the &lt;a href="http://go.microsoft.com/fwlink/?LinkId=55111"&gt;Visual Studio 2005 Web Deployment Projects&lt;/a&gt; [ http://go.microsoft.com/fwlink/?LinkId=55111 ] page on the ASP.NET Developer Center.&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Web application projects compile all code into a single assembly, so you do not need a Visual Studio 2005 Web Deployment project to combine assemblies. However, Web Deployment projects provide additional support for precompiling the .aspx content of a project, as well as for making post-build changes to the published configuration. Using the latest build of the Web Deployment project add-in, you will be able to do add these features for both Visual Studio 2005 Web site projects and Visual Studio 2005 Web application projects.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;&lt;a name="wapp_topic12"&gt;&lt;/a&gt;Scenario 2: Migrating a Visual Studio .NET 2003 Web Project to a Web Application Project&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This section walks you through the process of converting an existing Visual Studio .NET 2003 Web project to a Web application project in Visual Studio 2005. The Web application project model uses the same conceptual approach as a Web project in Visual Studio .NET 2003, including a project file to include and exclude files, compilation to a single assembly, and so on. In general, Web application projects do not require any architectural changes after the conversion.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;As in the preceding section, this section assumes that you are working in C#. The steps for working with Visual Basic are very similar, but file names and some of the code will differ.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;&lt;a name="wapp_topic13"&gt;&lt;/a&gt;Step 1: Install the Visual Studio 2005 Web Application Project Preview&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Be sure you have installed Web Application Projects in Visual Studio 2005 by following the steps in the &lt;a href="http://msdn.microsoft.com/#wapp_topic4"&gt;Installing Web Application Projects&lt;/a&gt; section earlier in this paper.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;&lt;a name="wapp_topic14"&gt;&lt;/a&gt;Step 2: Back Up Your Visual Studio .NET 2003 Projects&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Make absolutely sure to save a backup of your Visual Studio .NET 2003 Web projects and solutions before attempting any migration. The following steps have been tested using the preview version of Web Application Projects. However, there could still be issues, and you might need to restore the Visual Studio .NET 2003 solution.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;&lt;a name="wapp_topic15"&gt;&lt;/a&gt;Step 3: Open and Verify your Visual Studio .NET 2003 Web Project&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Before migrating a project, open your existing Visual Studio .NET 2003 solution, compile it, and then run it. Spending a few minutes to verify that everything works before you migrate can save trouble later, especially if the cause of errors is a last-minute directory change or similar.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;&lt;a name="wapp_topic16"&gt;&lt;/a&gt;Step 4: Migrate the Solution to Visual Studio 2005&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Close the solution in Visual Studio .NET 2003, and then start Visual Studio 2005. On the &lt;b&gt;File&lt;/b&gt; menu, click &lt;b&gt;Open File&lt;/b&gt;, and then browse to the .sln file for the solution you want to migrate. This launches the Visual Studio 2005 Conversion wizard:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img border="0" alt="" src="http://i.msdn.microsoft.com/Aa730880.wap_11(en-US,VS.80).gif" /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Figure 11. Visual Studio 2005 conversion wizard&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Click &lt;b&gt;Next&lt;/b&gt; to proceed through the wizard, accepting all defaults. Visual Studio 2005 will convert the solution and its contained project files to use the MSBuild format, which is the new project file format in Visual Studio 2005.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;As part of the migration, Visual Studio 2005 generates an XML-based log file that provides a summary of the conversion process, flagging any issues encountered during migration. By default, the conversion log file is saved in the same directory as the .sln file. If you have issues later when compiling the project, you might need to refer back to the conversion log file.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;&lt;a name="wapp_topic17"&gt;&lt;/a&gt;Step 5: Verify in Visual Studio 2005&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;After the solution and project files are upgraded to Visual Studio 2005 format, validate that your application builds without errors and runs as expected. At this point, the most common errors or warnings will be of these types:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;Conflicts with names in introduced in the .NET Framework version 2.0. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;Warnings about using obsolete members.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;To fix naming conflicts, you can either fully qualify existing names with a namespace to remove ambiguity, or rename the members so they do not conflict.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If you see a warning about using obsolete members, the warning message will usually suggest alternative APIs to use. In these cases, you can continue to use the obsolete members in the 2.0 version of the .NET Framework. However, the members will be removed in the next major release of the .NET Framework, so it is a good practice to remove the members and substitute the suggested alternatives.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;When running your Web application, you might see an error that says &amp;quot;Directory Listing Denied&amp;quot; that suggests that a virtual directory does not allow its contents to be listed. If you see this error message, do the following:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;  &lt;li&gt;Close the browser. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;In Solution Explorer, right-click the application's start page and then click &lt;b&gt;Set as Start Page&lt;/b&gt; to ensure that the correct page is invoked when the application runs. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;Run the application again.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;&lt;a name="wapp_topic18"&gt;&lt;/a&gt;Step 6: Covert Code-Behind Classes to Partial Classes&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;As noted earlier, in Visual Studio 2005, Web application projects use partial classes to store designer-generated code. These classes are stored in a separate file from the code-behind file. By default, the Visual Studio 2005 Web project conversion wizard does not create a *.designer.cs (or *.designer.vb) file for Web pages (.aspx files) or user controls (.ascx files). Instead, the code will look and work just like it did in Visual Studio .NET 2003.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;b&gt;Note&lt;/b&gt;&amp;#160;&amp;#160; The wizard makes the minimum number of changes to the code files during migration to help ensure a smooth conversion to Web application projects in Visual Studio 2005.&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;You can keep your code in this format. If you do, you must manually update the control field declarations in the code-behind files, but everything else will work fine in Visual Studio 2005.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;To take advantage of the editor's ability to maintain field declarations in generated code, you should update your pages and controls to use the partial-class model introduced in ASP.NET 2.0. Partial classes make it easier to organize the generated code and custom code for your code-behind files. For more information on .designer.cs files, see &lt;a href="http://msdn.microsoft.com/#wapp_topic6"&gt;Scenario 1: Creating a New Web Application Project&lt;/a&gt; earlier in this paper.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;To migrate your code to use partial-class model, first make sure that your code compiles without errors. Then in Solution Explorer, right-click the project name and click &lt;b&gt;Convert to Web Application&lt;/b&gt;. This command iterates through each page and user control in the project, moves all control declarations to a .designer.cs file, and adds event handler declarations to the server-control markup in the .aspx and .ascx files.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;b&gt;Note&lt;/b&gt;&amp;#160;&amp;#160; Another option is to use the &lt;b&gt;Convert to Web Application&lt;/b&gt; command on individual pages. You might do this first on a few pages if you want to watch closely the changes made for each page before applying the change to the entire application.&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img border="0" alt="" src="http://i.msdn.microsoft.com/Aa730880.wap_12(en-US,VS.80).gif" /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Figure 12. Converting a single page to Web application project format&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;When the process has finished, check the &lt;b&gt;Task List&lt;/b&gt; window to see if any conversion errors are reported. If the task list displays errors, right-click the relevant page in Solution Explorer and choose &lt;b&gt;View Code&lt;/b&gt;and &lt;b&gt;View Code Gen File&lt;/b&gt; to examine the code and fix problems. Note that errors and warnings that appear in the &lt;b&gt;Task List&lt;/b&gt; window persist between Visual Studio sessions. After you have fixed errors listed in the window, you can clear items from the task list.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;b&gt;Note&lt;/b&gt;&amp;#160;&amp;#160; The &lt;b&gt;Convert to Web Application&lt;/b&gt; command cannot be undone in Visual Studio. The best method for reverting the changes is to restore from a backup of the Visual Studio .NET 2003 project, and then to re-run the Visual Studio 2005 migration as described in Step 4 above.&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Now recompile your project to ensure it compiles without errors. A possible source of errors is if you have modified the control declarations in a code-behind class and the conversion wizard mishandles your changes.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;From this point, when you add new pages into your Web project, they will by default use the partial-class template.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;&lt;a name="wapp_topic19"&gt;&lt;/a&gt;Step 7: Examine and Resolve XHTML Compliance Issues&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;By default, Visual Studio 2005 generates and validates XHTML-compliant markup. This helps you build Web applications that are standards compliant and helps minimize issues with browser-specific rendering. Visual Studio .NET 2003 did not generate XHTML-compliant markup, so you might see validation and rendering issues with pages created in Visual Studio .NET 2003.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;b&gt;Note&lt;/b&gt;&amp;#160;&amp;#160; Validation errors are informational only and are flagged as warnings. Validation errors do not prevent a page from running.&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;If you do not want to see validation errors, switch the HTML validation setting from &lt;b&gt;XHTML Transitional to Internet Explorer 6.0&lt;/b&gt; (which was the Visual Studio .NET 2003 default setting). In the &lt;b&gt;Tools&lt;/b&gt; menu, click &lt;b&gt;Options&lt;/b&gt;. In the &lt;b&gt;Options&lt;/b&gt; dialog box, open the &lt;b&gt;Text Editor&lt;/b&gt; node, then the &lt;b&gt;HTML&lt;/b&gt; node, and then the &lt;b&gt;Validation&lt;/b&gt; node. In the &lt;b&gt;Target&lt;/b&gt; list, select &lt;b&gt;Internet Explorer 6.0&lt;/b&gt;, and then unselect the &lt;b&gt;Show Errors&lt;/b&gt; check box. Note that this does not fix XHTML validation errors; it simply switches the validation schema to one that is more compatible with the way markup was generated by Visual Studio .NET 2003, and it suppresses validation warnings.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;img border="0" alt="" src="http://i.msdn.microsoft.com/Aa730880.wap_13(en-US,VS.80).gif" /&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;Figure 13. Configuring HTML validation&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;You can also add the following section to your project's Web.config file, which causes ASP.NET to render legacy (non-XHTML compliant) markup from server controls:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;tt&gt;&amp;lt;system.Web&amp;gt;&lt;/tt&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;tt&gt;&amp;lt;xhtmlConformance mode=&amp;quot;Legacy&amp;quot; /&amp;gt;&lt;/tt&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;tt&gt;&amp;lt;/system.Web&amp;gt;&lt;/tt&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This will avoid the slight rendering differences you might see between pages displayed using ASP.NET 1.1 and using ASP.NET 2.0. For more information, see &lt;a href="http://go.microsoft.com/fwlink/?LinkId=64052"&gt;ASP.NET and XHTML&lt;/a&gt; [ http://go.microsoft.com/fwlink/?LinkId=64052 ] in the MSDN Library.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;&lt;a name="wapp_topic20"&gt;&lt;/a&gt;The Future of Web Application Projects&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Web application projects provide a compilation and build model very similar to the one used in Visual Studio .NET 2003. Depending on their requirements, some users will find the new Web site project option in Visual Studio 2005 more appropriate for their applications, while other users will prefer the Web application project option. Web application projects provide the best path for upgrading existing Visual Studio .NET 2003 applications to Visual Studio 2005, and are highly recommended for that scenario.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;We want to emphasize these important points about the future of Visual Studio 2005 Web application projects:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;Going forward, we will fully support both the Visual Studio 2005 Web site project model and Visual Studio 2005 Web application project model. You can choose whichever model works best for you. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;In future versions of Visual Studio, the Web application project model will be built in, and both the Web application project model and Web site project model will be supported.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;&lt;a name="wapp_topic21"&gt;&lt;/a&gt;Appendix A: Known Issues&lt;/h4&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This appendix lists known issues with Web application projects.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;&lt;a name="wapp_topic22"&gt;&lt;/a&gt;Issue 1: Data Scenarios&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;  &lt;li&gt;There are known issues when using data-bound controls and SQL Server 2005 Express with the April 2006 release of Web application projects. For a list of issues and workarounds, see the whitepaper named &amp;quot;Using Data-Bound Controls and SQL Server Express with Web Application Projects,&amp;quot; which is available on the &lt;a href="http://go.microsoft.com/fwlink/?LinkId=57541"&gt;Visual Studio 2005 Web Application Projects&lt;/a&gt; [ http://go.microsoft.com/fwlink/?LinkId=57541 ] page on the ASP.NET Developer Center.&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;&lt;a name="wapp_topic23"&gt;&lt;/a&gt;Issue 2: Visual Basic Inline Code Might Not Be Converted Correctly&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;When you upgrade a Visual Studio .NET 2003 project to Visual Studio 2005, Visual Basic code in single-file Web pages (.aspx files) or user controls (.ascx files) is not converted to use the new Visual Basic 2005 syntax. This can lead to compile time errors when building your converted Web project. You will need to manually fix these errors and recompile the affected pages. Visual Basic code in code-behind files is converted and should compile correctly.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;&lt;a name="wapp_topic24"&gt;&lt;/a&gt;Issue 3: WSE and Web Application Projects&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Web Services Enhancements (WSE) is an add-in to Visual Studio 2005 that provides the latest advanced Web services capabilities. When Web Application Projects is installed, the WSE configuration command on the shortcut menu in Solution Explorer will not work correctly. As a workaround, follow these steps to use the stand-alone WSE 3.0 configuration tool instead:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;  &lt;li&gt;Start the configuration tool. In the Windows &lt;b&gt;Start&lt;/b&gt; menu, click &lt;b&gt;All Programs&lt;/b&gt;, click &lt;b&gt;Microsoft WSE 3.0&lt;/b&gt;, and then click &lt;b&gt;Configuration Tool&lt;/b&gt;. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;In the configuration tool, in the &lt;b&gt;File&lt;/b&gt; menu, click &lt;b&gt;Open&lt;/b&gt;. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;Select the Web.config file for the project.&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;&lt;a name="wapp_topic25"&gt;&lt;/a&gt;Issue 4: Converting the Club Web Site Starter Kit (Visual Basic)&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;(This issue applies only when using Visual Basic.) When converting the Visual Basic version of the Club Web Site starter kit to a Web application project, you will see a run-time error similar to the following:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;Server Error in '/' Application.&lt;br /&gt;Compiler Error Message: BC30451: Name 'truncate' is not declared.&lt;br /&gt;Source Error: &lt;br /&gt;Line 129: &amp;lt;asp:Label ID=&amp;quot;Label2&amp;quot; runat=&amp;quot;server&amp;quot; Text='&amp;lt;%# truncate(CStr(Eval(&amp;quot;description&amp;quot;))) %&amp;gt;' /&amp;gt;&lt;br /&gt;Source File: C:\vs05\328\test-club1\wap1\Default.aspx    Line: 129&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;To resolve the error, you must add a namespace. You can do this for individual pages or for the project as a whole. Assuming your project namespace is &amp;quot;wap1&amp;quot;, follow these steps.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;h6&gt;To add a namespace to an individual page:&lt;/h6&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;  &lt;li&gt;Open the page. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;Under the last &lt;b&gt;@ Register&lt;/b&gt; directive, add an &lt;b&gt;@ Import&lt;/b&gt; directive that references the namespace you want to use, as in the following example:&lt;br /&gt;&lt;br /&gt;    &lt;pre&gt;&amp;lt;%@ Register TagPrefix=&amp;quot;Club&amp;quot; Namespace=&amp;quot;wap1.Clubsite&amp;quot; Assembly=&amp;quot;wap1&amp;quot;&amp;gt;&lt;br /&gt;&lt;tt&gt;&lt;b&gt;&amp;lt;%@ Import Namespace=&amp;quot;wap1&amp;quot; %&amp;gt;&lt;/b&gt;&lt;/tt&gt;&lt;/pre&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;h6&gt;To add a namespace to the project:&lt;/h6&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;  &lt;li&gt;Open the Web.config file. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;Add or edit the &lt;b&gt;&amp;lt;namespaces&amp;gt;&lt;/b&gt; element as a child of the &lt;b&gt;&amp;lt;pages&amp;gt;&lt;/b&gt; element, as in the following example:&lt;br /&gt;&lt;br /&gt;    &lt;pre&gt;&amp;lt;pages&amp;gt;&lt;br /&gt;&lt;tt&gt;&lt;b&gt;  &amp;lt;namespaces&amp;gt;&lt;/b&gt;&lt;/tt&gt;&lt;br /&gt;&lt;tt&gt;&lt;b&gt;    &amp;lt;add namespace=&amp;quot;wap1&amp;quot;/&amp;gt;&lt;/b&gt;&lt;/tt&gt;&lt;br /&gt;&lt;tt&gt;&lt;b&gt;  &amp;lt;/namespaces&amp;gt;&lt;/b&gt;&lt;/tt&gt;&lt;br /&gt;&amp;lt;/pages&amp;gt;&lt;/pre&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;&lt;a name="wapp_topic26"&gt;&lt;/a&gt;Issue 5: Converting the Personal Web Site Starter Kit (Visual Basic)&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;(This issue applies only when using Visual Basic.) When converting the Visual Basic version of the Personal Web Site starter kit to a Web application project, you will see a run-time error similar to the following:&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;Server Error in '/' Application&lt;br /&gt;The type specified in the TypeName property of ObjectDataSource 'ObjectDataSource1' could not be found&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;To resolve the error, you must add the project namespace to the &lt;b&gt;TypeName&lt;/b&gt; property. Assuming your project namespace is &amp;quot;wap1&amp;quot;, follow these steps.&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;  &lt;li&gt;Open the Member_List.aspx page. &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;  &lt;li&gt;Change the type name in the &lt;b&gt;ObjectDataSource&lt;/b&gt; declaration to be fully qualified, as in the following example:&lt;br /&gt;&lt;br /&gt;    &lt;pre&gt;&amp;lt;asp:ObjectDataSource TypeName=&amp;quot;&lt;tt&gt;&lt;b&gt;wap1.&lt;/b&gt;&lt;/tt&gt;MemberDetails&amp;quot; &amp;gt;&lt;/pre&gt;&lt;br /&gt;  &lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;&lt;h5&gt;&lt;a name="wapp_topic27"&gt;&lt;/a&gt;Issue 6: Converting a Visual Studio 2005 Web Site project to a Web Application Project&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;This paper will be updated in the future to show the steps needed to convert a Visual Studio 2005 Web site project to a Web application project. In the meantime, see the entry, &lt;a href="http://webproject.scottgu.com/CSharp/migration2/migration2.aspx"&gt;Tutorial 8: Migrating from VS 2005 Web Site Projects to be a VS 2005 Web Application Projects&lt;/a&gt; [ http://webproject.scottgu.com/CSharp/migration2/migration2.aspx ] on Scott Guthrie's blog.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-2629736609569480046?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/2629736609569480046/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2009/07/comparing-web-site-projects-and-web.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/2629736609569480046'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/2629736609569480046'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2009/07/comparing-web-site-projects-and-web.html' title='Comparing Web Site Projects and Web Application Projects'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-1354909896215950833</id><published>2009-06-30T19:37:00.001-07:00</published><updated>2009-06-30T19:39:04.557-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='Tricks'/><category scheme='http://www.blogger.com/atom/ns#' term='Technology News'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Architecture / Design'/><title type='text'>Fast version of the Activator.CreateInstance method using IL</title><content type='html'>&lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://mironabramson.com/blog/file.axd?file=FastObjectFactory.zip"&gt;FastObjectFactory.zip (50.35 kb)&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Source: &lt;a href="http://mironabramson.com/blog/post/2008/08/Fast-version-of-the-ActivatorCreateInstance-method-using-IL.aspx"&gt;http://mironabramson.com/blog/post/2008/08/Fast-version-of-the-ActivatorCreateInstance-method-using-IL.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;We all know (I guess) the method Activator.CreateInstance(Type) and the generic version:&amp;#160; Activator.CreateInstance&amp;lt;T&amp;gt;()&amp;#160; that are used to create an instance of a specified Type.&lt;/p&gt;  &lt;p&gt;In now days all are talking about '&lt;a href="http://en.wikipedia.org/wiki/Entity-relationship_model"&gt;Entity-relationship model&lt;/a&gt;' , '&lt;a href="http://en.wikipedia.org/wiki/Object-relational_mapping"&gt;Object-relational mapping&lt;/a&gt;' and that stuff, that basically it means getting a IDataReader, loop over it and fill with the data a List with specfied type of objects and return a List instead of DataSet or DataTable (or similar mechanism). While looping over the IDataReader, every iterate, an instance of the specified type needs to be create. It can be done using one of the methods above, but it can be improved by usind IL and some help using some cache. Here is how can it be done:&lt;/p&gt;  &lt;p&gt;public static class FastObjectFactory   &lt;br /&gt;{    &lt;br /&gt;private static readonly Hashtable creatorCache = Hashtable.Synchronized(new Hashtable());    &lt;br /&gt;private readonly static Type coType = typeof(CreateObject);    &lt;br /&gt;public delegate object CreateObject();    &lt;br /&gt;/// &amp;lt;summary&amp;gt;    &lt;br /&gt;/// Create an object that will used as a 'factory' to the specified type T&amp;#160; &lt;br /&gt;/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;    &lt;br /&gt;public static CreateObject CreateObjectFactory&amp;lt;T&amp;gt;() where T : class    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Type t = typeof(T);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; FastObjectFactory.CreateObject c = creatorCache[t] as FastObjectFactory.CreateObject;    &lt;br /&gt;if (c == null)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;lock (creatorCache.SyncRoot)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; c = creatorCache[t] as FastObjectFactory.CreateObject;    &lt;br /&gt;if (c != null)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; {    &lt;br /&gt;return c;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; DynamicMethod dynMethod = new DynamicMethod(&amp;quot;DM$OBJ_FACTORY_&amp;quot; + t.Name, typeof(object), null, t);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ILGenerator ilGen = dynMethod.GetILGenerator();    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ilGen.Emit(OpCodes.Newobj, t.GetConstructor(Type.EmptyTypes));    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ilGen.Emit(OpCodes.Ret);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; c = (CreateObject)dynMethod.CreateDelegate(coType);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; creatorCache.Add(t, c);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;return c;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }    &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;Note the static HashTable is been used as a cache. The first&amp;#160; time we create a delegate 'CreateObjec' for the given type it is 'slow', so all the point here, is to cache this delegate. The next time we need to create an object from the given type, the 'CreateObjec' delegate will be used from the cache. Without caching it, the whole story worth nothing.&lt;/p&gt;  &lt;p&gt;Here are some benchmarks:&lt;/p&gt;  &lt;p&gt;1 Object:&lt;/p&gt;  &lt;p&gt;&lt;img alt="" src="http://mironabramson.com/blog/image.axd?picture=OneIterate.jpg" /&gt;    &lt;br /&gt;100 Objects:&lt;/p&gt;  &lt;p&gt;&lt;img alt="" src="http://mironabramson.com/blog/image.axd?picture=100Iterates.jpg" /&gt;&lt;/p&gt;  &lt;p&gt;1000 Objects:   &lt;br /&gt;&lt;img alt="" src="http://mironabramson.com/blog/image.axd?picture=1000Iterates.jpg" /&gt;&lt;/p&gt;  &lt;p&gt;Comparing to the generic constraint : new()&lt;/p&gt;  &lt;p&gt;&lt;img alt="" src="http://mironabramson.com/blog/image.axd?picture=banchmark.jpg" /&gt;&lt;/p&gt;  &lt;p&gt;Below there is the small project I used for the benchmarks:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://mironabramson.com/blog/file.axd?file=FastObjectFactory.zip"&gt;FastObjectFactory.zip (50.35 kb)&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Source: &lt;a href="http://mironabramson.com/blog/post/2008/08/Fast-version-of-the-ActivatorCreateInstance-method-using-IL.aspx"&gt;http://mironabramson.com/blog/post/2008/08/Fast-version-of-the-ActivatorCreateInstance-method-using-IL.aspx&lt;/a&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2559055593203508155-1354909896215950833?l=developers-house.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://developers-house.blogspot.com/feeds/1354909896215950833/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://developers-house.blogspot.com/2009/06/fast-version-of-activatorcreateinstance.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/1354909896215950833'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2559055593203508155/posts/default/1354909896215950833'/><link rel='alternate' type='text/html' href='http://developers-house.blogspot.com/2009/06/fast-version-of-activatorcreateinstance.html' title='Fast version of the Activator.CreateInstance method using IL'/><author><name>Admin</name><uri>http://www.blogger.com/profile/14719678373035290012</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2559055593203508155.post-6033811228073269063</id><published>2009-06-30T00:19:00.001-07:00</published><updated>2009-06-30T00:19:56.766-07:00</updated><title type='text'>SQL Server 2005 Paging – The Holy Grail</title><content type='html'>&lt;p&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The paging and ranking functions introduced in 2005 are old news by now, but the typical ROW_NUMBER OVER() implementation only solves part of the problem.&lt;/p&gt;  &lt;p&gt;Nearly every application that uses paging gives some indication of how many pages (or total records) are in the total result set. The challenge is to query the total number of rows, and return only the desired records with a minimum of overhead? The holy grail solution would allow you to return one page of the results and the total number of rows with &lt;i&gt;no&lt;/i&gt; additional I/O overhead.&lt;/p&gt;  &lt;p&gt;In this article, we're going to explore four approaches to this problem and discuss their relative strengths and weaknesses. For the purposes of comparison, we'll be using I/O as a relative benchmark.&lt;/p&gt;  &lt;p&gt;&lt;b&gt;The 'two-bites' approach&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;The most basic approach is the 'two-bites' approach. In this approach you, effectively, run your query twice; querying the total rows in one pass, and querying your result set in the second. The code is pretty straightforward:&lt;/p&gt;  &lt;p&gt;DECLARE @startRow INT ; SET @startrow = 50   &lt;br /&gt;SELECTCOUNT(*) AS TotRows    &lt;br /&gt;FROM [INFORMATION_SCHEMA].columns&lt;/p&gt;  &lt;p&gt;;WITH cols   &lt;br /&gt;AS    &lt;br /&gt;(    &lt;br /&gt;SELECT table_name, column_name,    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ROW_NUMBER() OVER(ORDER BY table_name, column_name) AS seq    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; FROM [INFORMATION_SCHEMA].columns    &lt;br /&gt;)    &lt;br /&gt;SELECT table_name, column_name    &lt;br /&gt;FROM cols    &lt;br /&gt;WHERE seq BETWEEN @startRow AND @startRow + 49    &lt;br /&gt;ORDERBY seq&lt;/p&gt;  &lt;p&gt;It gives the desired resul
