Wednesday, February 3, 2010

Code conversion from SharePoint 2007 to SharePoint 2010

SharePoint 2010 is extended platform and supports most of the framework of MOSS 2007. So converting the code from 2007 to 2010 is really not a big deal.

But still few important things to note/tips are listed here Preparing environment

Important things to note:
-- Ensure that you have Administrators rights on the machine , you want to use for Development.
-- Use standalone machine for Development , this will save you lot of time dealing with networking issues and also time for deploying/retracting solution cycles.
-- Run all the Windows update on the machine to make sure you have the latest build and hot fixes.

Solution setup Steps:
1. Launch the Visual Studio 2010

2. File > New Project > SharePoint > Empty SharePoint project > Specify a Name of the project Make sure you have Framework 3.5 selected from the drop down In case you get prompted for missing Administrator rights and need Restarting the Visual Studio as Administrator, please go ahead and do that.

3. File > New Project > SharePoint > Empty SharePoint project > Specify a Name of the project Make sure you have Framework 3.5 selected from the drop down You might be prompted that same Folder name already exist ( from your previous attempt ), so delete the existing folder or specify a new name.

4. You will be presented with SharePoint Customization Wizard as shown below. Specify the Url to the site collection you want to use for Debugging , make sure to Validate. Select Deploy as a farm solution.


This will get you a new SharePoint based project with Zero Features with No SharePoint items ( also known as SPI's ).

1. Click on the project Add > New Item > SharePoint

2. Select WebPart > Specify a name of the Web part

3. You will see new folder added with the name specified above for the Web part

4. Also you will see new folder name "Feature1" added under Features folder

5. Click on Feature1 > Check the properties window > Change the Folder name same as name of WebPart used in step2. This is update the files and folder name automatically.

6. Right click the project name > Deploy to test if deployment is smooth.

7. Once deployment succeed.

8. Navigate to the site collection you are using for debugging.

9. Edit the page and click on Add web part 10. Locate your custom webpart under Custom category > Select the Webpart > Add Webpart to the page to test.

Enhancement Steps:
Once full deployment cycle is tested , Navigate back to Visual Studio project.
At this stage we have the working 2010 solution project created and will start moving more functional components in the project.

1. Open the .cs file and start adding more functionality to the webpart to the methods like CreateChildControl , RenderContent etc.

2. Also Add other helper files ( resources / webcontrol files etc ) from 2007 project. At this point if you are using Layout based items , create a Mapping folder for Layouts/Images ( Right click project > Add > SharePoint mapping folder for Layouts/Images ).

3. Ensure you have the consistent Namespaces to avoid any build errors.

4. Do a code walkthrough to make sure you have write file path location for various dependent assets like css/js/image files.

4. Build often and if build is smooth , Deploy often to make sure , code builds fine and changes are as expected.