Monday, January 28, 2008

Creating web application and web site that run in IIS 7 of windows vista from vs2008

While creating a web site in vs2005 or vs2008 , web site location has three options and the options are 1. File System 2. HTTP 3. FTP

image

Previous version of Visual studio (VS2002,VS2003) supports web application that run only on IIS. User can easily create web applications cause Visual Studio automatically guide the user to create a web application. Since vs2005 come with whole new application suite for example, Web Site template , web application template and mix mode of Ajax templates user had options to chose between many things. I personally used IIS and File System web site and web applications (File System web run on Vs integrated vs development web server ) in windows XP. I have recently moved to windows vista and and VS2008 Team System. I found some interesting stuff regarding windows vista and vs2008 that I thought need little share with the community (might help some one).

Web site in VS2008 on windows vista that run on IIS

image

I wanted to create a web site in IIS so I opened vs2008 selected ASP.net "Web Site" project template and Choose Local IIS but I found a strange message and unable to proceed to create a virtual directory from the wizard. I didn't read the message carefully, I thought my IIS is not installed properly or my IIS is not running. I opened my IIS administration MMC from administrator tool and found that IIS is up and running well, then I got confused and performed the same site creation operation again. This time when the Local Internet Information Server tab got selected I read the message carefully and it says how to create web site from vs2008, and it says I got to run vs2008 with "Run as administrator" :)

image

I closed my IDE and opened IDE from start menu with "Run as administrator" options selected from right click menu and performed the same operation again, this time every thing worked just okay :).

image

Web app in VS2008 on windows vista that run on IIS

While creating a "web application" project (which is created via choosing new project, rather than new web site from File->New menu) user do not have any option to select between File system or IIS hosted project in project creation wizard. By Default a File System based web application is created for the user. Just follow the normal procedure to create a web application, after web application creation is completed select the project properties. When the project properties window appear select the Tab named "Web*". You will see in web tab by default "Use Visual Studio Development Server" option is selected. change it to "Use IIS Web Server" option. After that just click on the Create Virtual Directory button to finish the procedure. save the project and you are good to go.

image

Oh one more thing, for this operation, again you have to run IDE in Run as administrator mode.

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.

image

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.

image

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.

image

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.

image

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.

image

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.

http://msdn.microsoft.com/en-us/library/ms165392%28v=vs.80%29.aspx

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

image

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.

image

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

image

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

image

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.
www.assembla.com
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 http://www.assembla.com/ 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.
www.sourceforge.net
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:
https://bitbucket.org/ is now offering unlimited private project hosting... awesome