Friday, December 7, 2007

Visual studio as database designer

Visual studio have now supports working with data extensively. I mean the feature was there from the beginning but how the UI and interaction is perfected. For instance lets say we don’t have any sql server 2000 database, or even no MSDE database. Not even the new express database that came with the default installation. Still we have the “filename.mdf” the file based SQL Express database support. and to work with that we only need visual studio to SQL Server management studio is necessary. All the purpose of normal developer work can be achieved by visual studio.

For instance create a mdf database. Then work on creating tables, views, store procedures, functions, and what not. Bellow I have provided a screen shot, that is been lunched right after you create a mdf file based database.


Visual also have some rich table creating and manipulate facilities. When we create a mdf file based db, it automatically creates a data connection for us in server explorer. Note that we can also connect to SQL server express, sql server, oracle , odbc and any database with a supported provider.


One key improvement is that not only we can create and modify any kind of database object in visual studio but also we can attach sql debugger to step in to store procedure to to see what is happening inside the query.


There are many more database related feature in visual studio and looks like its moving towards perfection as a IDE. But I have a concern though, when the IDE will be perfect obviously It would be performance issue, the big guys from MS should look after it.

Friday, November 2, 2007

Some common code Snippets in visual studio (prop,ctor,try, etc.)

Probably every one knows about it but still want to share a simple feature that I though really good is code snippet. it’s a help tool to generate small portion of code using key word then tab.


to use this just type “ctor” in your class and then press tab, this will automatically generate code for you. bellow some common snippet key word is given.

  • ctor (constructor)
  • prop (property)
  • propg (read only property)
  • using (using block)
  • while,do (for loop block)
  • try, tryf (for try catch and try finally block)

There are more, you can find all of them in intelligence context menu. Lets finish this post by another information worth knowing is that the “Surround With” and “Insert Snippet” content menu item. You can also use this to warp your codes with region conditional pre-compiler switch and many more.


Please visit the resource bellow on MSDN to know more about how to use custom snippet. It has full resource how to customize the snippet feature and you can create and distribute your own code snippet.

Friday, October 5, 2007

Refactoring in visual studio

Why refactor? you know better why, because we have written crappy codes and its making our life hell, and killing lots of precious development hours. we could write thousands of line just to describe why we need refactoring, but lets not go in that debate.

We are here to learn refactoring features provided by visual studio to clean up our codes. The refactoring techniques are given bellow.

  • Rename
  • Extract Method
  • Encapsulate Field
  • Extract interface
  • Promote Local Variable to Parameter
  • Remove parameters
  • Reorder parameters

Bellow a screen shot from visual studio is given


All of the refactoring have shortcut associated with it and all of them are two key shortcut. Starts with CTRL+R, and followed by CTRL+”ANY Main Key”. for instance R is for Rename. Bellow example of rename refactor is given.

Rename Refactor

Step 1: Select the class, property, variable, field, or method. hit CTRL+R followed by CTRL+R, a window will popup and then put required name then click ok. if preview is been selected, it would popup another window.


Step 2: A preview will be shown what the ide will going to do with the name provided. Click apply to proceed.


This is just a tip of the iceberg. There are huge possibilities with this new features, how we use it and whether we choose to use it or not totally depends on us. And I highly recommend to use this refactor feature more and more.

Friday, September 7, 2007

Logical grouping of projects using solution folders.

Its unlikely that any of our professional life projects have only one project in our solution, and likely that in every of our project we would have huge number of projects in it. It might get hectic for us to keep track of the projects and find it in a glance, moreover it not healthy for the project also.

Visual studio have a nice feature called “Solution Folder” which is a logical folder structure and does not have any physical existence in user’s disk. Bellow I have given a screen shot of one of my personal project, where I have categorized three part of my solution using solutions explorer.

  • Architecture
  • Infrastructure
  • UI


In architecture I kept Business logic, data access layer and service layer. In infrastructure I kept helpers and business objects project and finally in UI solution folder I kept the web ui and window ui project. There could be more folder like this for instance “deployment” where all installer projects will go.

If solution folder had physical existence it would have been more helpful for us. But whatever we have serves our purpose.

Friday, August 3, 2007

How to get a free SVN repository?

Why we need SVN or any kind of source control, off course we  want to keep our source safe and want to maintain our source so that no one can see our private code. One easy step is to private SVN repository in your local network. In this particular scenario we have to install server all by yourself, all backup and labeling needs to be done all by our self as well.
It would be nicer if we have hosted SVN repository where we can keep our source as private, all backup and system recovery solutions will be provided by the hosting company. Luckily there are some services in the internet for that, for instance is a wonderful site which allows commercial trails and if you have a open source project you can get a free SVN repository. You can also get limited space of around 250mb of free personal private SVN repository.
Yet another solution is to use Source forge or other free open source code hosting sites, note that we need to confirm what kind of open source SVN they support.
Unfortunate thing is that I kind find a good Microsoft based, source control on internet for free, that would be a nice addition to the open source work force.
Update 1:
Now we can host code in google code and also have svn support, but code needs to be open source.
Update 2:
Now we can also host code in codeplex which is sponsored by Microsoft. In this case code needs to be open source.
Update 3:
CodePlex now support team foundation server and teamexplorer of VS2008
Update 4: is now offering unlimited private project hosting... awesome

Thursday, July 5, 2007

How to Add Web Application Project in Visual Studio 2005.

The new version of visual studio does not content the web application project template, which was available in visual studio 2003. The way you can create web project is to create a new web site. I have no idea why its like that but the web application project was cooler than web site template.

Anyway may be Microsoft wanted to try new things. But there is always a work around for the problems, you can download the web application project template from  here. Installing this project template would give you web application project template for both c# and

Update 1:

We found a very cool web site about Visual studio web application project template and lots of help with it. Thanks to Scott Gu. He have provided a awesome site with lots of tutorials.


Please visit Visual Studio 2005 Web Application Project for more information.

Update 2:

Never mind the old stuff web project is now available with the latest service pack. Life would be lot easier if they had provided it earlier.


Thursday, June 21, 2007 File Upload Control Using with just one step

In our projects sometimes we need to use the file upload control. 2.0 have
a build-in File-upload. In 1.x web controls didn’t had any builtin file-upload
control. Then we had to use a html input tag with type attribute set to “file” and
to use in server side add runat=”server” attribute.

<input id="myfileuploader" type="file" runat="server"/>

We all know how to work with a file upload control, today we will be discussion
about a new approach of file-upload. file-upload consists of two step . first we
have to select the file and then submit the page with a button or some kind of other
mechanism. To day we will try to minimize one step. If we want to upload the file
with just one step that is selecting the file here is the Technique

A file upload control which is eventually truned into a input html element have
three client side events

    * onBlur      
    * onChange
    * onFocus

we will utilize the onChange event… here is what we will do. frist add a
2.0 fileupload control in our page. then in pageload event add a attribute in attribute
collection. then write a javascript funtion to submit the form and in code do what
ever we whan….

task 1 : add a fileupload control

task 2: add the onchange attribute as FileUpload1.Attributes.Add("onchange", "doSomeStuff()");

task 3: add the javascript to submit the page

<script language="javascript"

function doSomeStuff()




Thats it you are good to go.. in page load event check wheither the filename is
empty or not and then do the file upload.

Wednesday, May 2, 2007

Select Items of a html Select

As you all know in asp .net when we define a dropdown list it is converted to a html select.

<asp:DropDownList id="ddlNewsLetter" runat="server"></asp:DropDownList>

Now in html…

Its look like this

<select name="GcbsUC:ddlNewsLetter" id="GcbsUC_ddlNewsLetter">
<option value="1">July 11, 2006</option>
<option value="2">June 14, 2006</option>
<option value="3">May 14, 2006</option>
<option value="4">April 9, 2006</option>
<option value="5">March 16, 2006</option>
<option value="6">February 19, 2006</option>

In C# code i have populated the dropdown list with a counter and a data…

Well if we what to select a perticular dropdown item from the list… how we do it…


1 . document.getElementById(‘ControlName’).selectedIndex = ‘ourvalue’; [here ourvalue must be an integer and between a range of the options.length.

2. document.getElementById(‘ControlName’).value = “ourknownvalue”;

[here ourknownvalue can be 6 that is <option value="6">February 19, 2006</option>]

3. well can can always loop through the items and do what ever we like with the property


Here is an example

var ddlNewsLetter = document.getElementById('ddlNewsLetter');
for(var i=0; i < ddlnewsletter.options.length; i++)
if(ddlnewsletter.options[i].text == strnewsletterdate)
ddlnewsletter.options[i].selected = true;

Wednesday, April 11, 2007

VS 2005 Windows Work Flow ToolBox Section...

Hi Recently i had to work with Windows workflow foundation for some conceptual demo or proof of concept demo. During development time i faced a strange problem. some of the windows workflow tools are not showing in tool box.




I try to reinstall the workflow extention for Vs2005 but the problem remain. if you see care fully i can not drag and drop a code activity from the tool box. That was a little but disturbing … then i reset the tool box. and every thing got back on line again. i just right click on the tool box a popup menu come up which has a reset menu item.




Some time in some other extention of vs this thing can happen. Dont forget to reset your tool window.

Saturday, March 3, 2007

Install assembly into Global Assembly Cache

Option One

Step One add the sn.exe to External Section of VS2005

1. Click on Menu->Tools->External Tools
2. A window with all external tool listed will popup.. click on add button
3. In title type “String Name tool”
4. In command brows for sn.exe tool [Generally in the bin directory of your sdk folder]
5. Check the use output window and prompt for argument check box…
6. Click on apply to dismiss the widow…

Now you can see that in tools menu you will have a menu item named “Strong Name Tool”. Click on the menu will launch a window asking the argument …. In the argument text box type

–k “c:\\mykeypair.snk”Click on okey to dismiss the window… in output window you will see that successful keypart creation message will be shown…

Your key is reated but not yet associated with any

Adding the key to the project to associate with assembly1. Open your project…
2. Open the property of the project…
3. You will see a tab called signning is bottom of the window… click on the signning button
4. In siginning tab check the sign the assembly check box.
5. In choose a strong name key file … click on brows …. And brows for your mykeypair.snk file…
6. save the project and build it…

That’s it your assembly is strong name signed on….

Option Two [Too Easy]

1. Open your project…
2. Open the property of the project…
3. You will see a tab called signning is bottom of the window… click on the signning button
4. In siginning tab check the sign the assembly check box.
5. In choose a strong name key file … click on new…
6. A window asking for snk file will popup… type the desiered name and click on okey to dismiss the window… save the project and build it…

That’s it your assembly is strong name signed on….

Deploy the assembly in GAC…

1. Add the gacutil.exe tool just like the sn.exe tool
2. Now open the gacutil tool from tools….
3. In the argument window type….
4. -i "$(ProjectDir)\bin\debug\DataBaseHelper.dll" or [-I “yourprojectdir\buildmode[debug or release]\bin\filename.dll”]
5. Click on okay to dismis the window..
6. In output window you will see a successful message….
7. “Assembly successfully added to the cache”

Happy programming!

Monday, February 19, 2007

CSS Problem of Ajax Tool Kit Calendar

AjaxControlTookKit is a very nice addition of 2.0 Ajax Extension. Recently I had very nice experience using 2.0 Ajax in few of my projects. "update panel" is very use full control as far as easy Ajax is concern. I haven't explored the whole area of client side scripting, but so far the experience with the server side controls are pretty much good and satisfactory.

Problem with Calender

In one of my project, I had to use the Calendar Extender of Ajax. Well in the page level the Calender Extender worked fine. but when i put the extender in one of my usercontrol. after the page render in browser the calender popup's position is pretty strange. No deterministic behavior was found in popup. when I click on the button of the calender the popup window appeared way up where it should actually show.

I went on trying few things to fix the thing and succeed on the setting position to relative. I just put the position behavior of the parent div of the Extender to relative.


worked like cramp

Another problem

If you set the css property of the calender extender suddenly the calender loose all its default behaviour and color skim. And no detail guide line is found in the site for customizing the style of the calender control.

Since ajaxControlToolKit is under development we hope this issues will be fixed in the actual release product.

Thursday, January 25, 2007

VS templates not working? Easy to get things back.

Recently I had to work with window SharePoint Service 3.0 and its development. I download the visual studio 2005 project templates for SharePoint development. I downloaded the project msi from Microsoft download site.

Installed in my local computer… but when I opened the IDE2005 project templates are not there…..

I got confused… and try reinstall the msi… but noting happed… I went to google and found few people is also suffering from this problem… the problem is my vs2005 is installed in different drive other that “c:\” and the installed temples are in default “c:\”… and then I moved my template in the drive where the IDE2005 is installed….

Location of the project templates is [your dive letter]:\Program Files\Microsoft Visual Studio 8\Common7\IDE…

There were two directories one if project template and other is item template… last thing that I did is to make ide identity the project templates….

For this I had to just a command in vs2005 comma prompt..

devenv /installvstemplates

I found help from the following forum… please go there for more detailed discussion…

Hope this will help someone someday….

Friday, January 5, 2007

Bubble Sort


Bubble sort, also known as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. Because it only uses comparisons to operate on elements, it is a comparison sort. Although the algorithm is simple, it is not efficient for sorting large lists; other algorithms are better.

Pseudo Code

The pseudo code of the bubble sort is given bellow.

procedure bubbleSort( A : list of sortable items )
swapped = false
for i = 1 to length(A) - 1 inclusive do:
if A[i-1] > A[i] then
swap( A[i-1], A[i] )
swapped = true
end if
end for
until not swapped
end procedure


Bubble sort has worst-case and average complexity both О(n2), where n is the number of items being sorted. There exist many sorting algorithms with substantially better worst-case or average complexity of O(n log n). Even other О(n2) sorting algorithms, such as insertion sort, tend to have better performance than bubble sort. Therefore, bubble sort is not a practical sorting algorithm when n is large.

The only significant advantage that bubble sort has over most other implementations, even quicksort, but not insertion sort, is that the ability to detect that the list is sorted is efficiently built into the algorithm. Performance of bubble sort over an already-sorted list (best-case) is O(n). By contrast, most other algorithms, even those with better average-case complexity, perform their entire sorting process on the set and thus are more complex. However, not only does insertion sort have this mechanism too, but it also performs better on a list that is substantially sorted (having a small number of inversions).


Simulation #1:




More online simulation


Implementations of the bubble sort is given bellow. For now we have only three supported language, in future we would try to incorporate more implementations.

Code Sample in “c”

Real implementation in c is given bellow.


void bubble(int a[],int n)
int i,j,t;


}//end for 1.

}//end function.

void main()
int a[100],n,i;


printf("\n\n Enter integer value for total no.s of elements to be sorted: ");

for( i=0;i<=n-1;i++)
{ printf("\n\n Enter integer value for element no.%d : ",i+1);


printf("\n\n Finally sorted array is: ");
for( i=0;i<=n-1;i++)

} //end program.

Code Sample in “c++”

Bellow a simple implementation of bubble sort in c++ is given.

#include <stdio.h>
#include <iostream.h>

void bubbleSort(int *array,int length)//Bubble sort function
int i,j;
int temp=array[i]; //swap

void printElements(int *array,int length) //print array elements
int i=0;

void main()
int a[]={9,6,5,23,2,6,2,7,1,8}; // array to sort
bubbleSort(a,10); //call to bubble sort
printElements(a,10); // print elements

Code Sample in “c#”

The c# implementation is given bellow.

namespace AllAlgorithm
public class BubbleSort
private readonly int[] _samples = new int[100];
private int x;
public void SortArray()
int i;
int j;
for (i = (x - 1); i >= 0; i--)
for (j = 1; j <= i; j++)
if (_samples[j - 1] > _samples[j])
int temp = _samples[j - 1];
_samples[j - 1] = _samples[j];
_samples[j] = temp;