Saturday, September 22, 2012

Migrating SharePOint 2007 Workflows to Sharepoint 2010

Hi folks, I am back again with yet another post and I will be talking about migration of sharepoint workflows from 2007 to 2010 environment. Now for migrating sharepoint 2007 site and apps to 2010 environment, one of the most popular and logical way used is database detach and attach method. Details mentioned below:
Step 1: Create same sites with same structures in Sharepoint 2010 environment.

Step 2: After taking the backup of the SharePoint 2007 content and other databased exlcluding the Config DB, detach the databases from thir respective sites.

Step 3: Move the Content DB's to SharePoint 2010 environment and replace the Content DB;s of newly created sites with the these DB's from SharePoint 2007 env.

Step 4: Now after attachig these databases to the content db of the new sites and apps in new server you will find all the content and sites running in SharePOint 2010 environment updated!

Here you complete the process of migration but all is not done yet. It is because when you use some third party controls, tools or software or even the FBA authentication in your sites it will require you some extra efforts to enable them back in SharePoint 2010. In this post I will be focussing specially on Workflows.

So once the above steps are done we are left with migrating the code. You may follow the simple steps metioned below. I would like you to read it all once before going to make any actual change. Also note that the steps are not actually long but I have divided them just to simplify things!

Steps:

1. Create a Sequential Workflow using Visual Studio 2010 in SharePoint 2010 dev machine. Please note to use the same name of the list or document library in which the workflow is currenly running on the SharePoint 2007 environment, otherwise the workflow may not work!

2. After you create the workflow in SP 2010 using Visual Studio 2010 you will be left with the basic template and folder sturcture in Visual Studio Solutions view. Please also note that you choose Farm Deployment while creating Workflow and not the Sandbox solution.

3. Now, copy the SP 2007 project developed using VS 2008 to the SharePoint 2010 machine where you are creating the workflow and want to migrate the code to current environment.

4. Right Click on Visual Studio 2010 solution from the Solution explorer to add an existing project. Under this browse to the location where you have copied the Sharepoint 2007 workflow project and finally add it in the VS 2010 solution.

5. Delete the contents of the Worklfow.cs file and other related files from the Workflow folder in the VS 2010 project. Please don't delete the folder. Now drag-and-drop the workflow.cs and other contents of the same workflow folder but from the Visiual Studio 2008 project into folder where you just deleted the contents (VS2010 project).

6. Once you are done with that, create a new folder structure by adding a new folder in the newly created project of (SP2010). Create a folder '14' and then beneath it 'TEMPLATE' and under that 'FEATURES'.

7. Under the features folder Drag-and-Drop the feature folder(s) with their xmls from the SP2007 project to SP2010 project.

8. Now Add all required web references in the SP2010 project which your code might be using or referring.

9. Remove the SP2007 projects and it's contents from the VS2010 solution.

10. Now you may change the namespaces in each file according to the newly created namespace in VS2010 or you may alternatively change the names space of VS 2010 solution with respect to the name spaces you used in SP2007 worklow. I did the later because it was easier and time saving.

Now build the code and you are ready to go!

In case you are creating a new Assembly key you will have a new public key generated for the dll and therefore, please remember to reference it in all the aspx pages.

Saturday, August 25, 2012

How to do Bulk Approvals in Sharepoint custom workflow developed using Visual Studio

As you might be aware that Sharepoint is a great tool which is used by almost all enterprises these days. One big & solid reason as why it has become such a hit is that, it integrates well with the Microsoft's infrastructure which can't be ignored! The other, it helps the enterprises to enable their business process smoothly and enforce the same among it's emaployees to carry out their operations properly. In face we ca say that the businesses run on Sharepoint if it helps to business to operate properly!
One of the most popular use of Sharepoint 2007 / 2010 is enabling business process in an organization using worklows. Sharepoint allows great ways to customize and build enterprise class application and business process to be converted in an easy to use, familiar, well integrated secured infrastructure of Micorsoft.

I have been involved in developing workflows using Sharepoint for over 3 years by now. Recently, my team got a requirement from the business that required workflow approvals to be done in bulk i.e bulk approvals of sharepoint workflows. You might me thinking of it as complex scenario as we also thought it like that. But, to my surprise and intuitive guess it turned out to be a whole lot easier! I will explain below what I did in simple steps to you:

1. I used a Grid View control to display all the tasks assigned to an approver in a new page.
2. Put Check box control to each row in the grid view and placed Approve and Reject buttons at the bottom of the page.
3. Next step was to get all selected tasks in a for loop when the user selected tasks using check boxes from the grid view and clicked Approve or reject button. (pretty simple so far!)
4. On button click I took all the grid view rows in the loop and catched the selected rows ID.
5. From the ID of the task I used AlterTask () method to call On Task Changed activity code/functionality. I set the boolean variable to true in case of Approvals and false in case of Rejection. I used this boolean value in my workflow logic to move or proceed the workflow to the next level in case it is True, and terminate or stop it in case it is Rejected (boolean value False).

To my surprise my code worked wonderfully and all the tasks got approved and rejected very smoothly!
Note the key here is to fire the AlterTask() for each selected row in the grid which we use anyways to fire the ChangeTask Activity using the task approvals or task edit forms.
I tried to Google it a lot before trying out this idea by using keywords like Bulk approvals of sharepoint workflow or batch approvals of sharepoint workflow tasks but I didn't get any clue. Finally, I tried this POC and it worked. I am sharing the same so that you may not have to stumble upon much.

Please note that the above solution presented is developed for SharePoint 2007 using Visual Studio 2008. Please feel free to contact me in case you need the working code also. Happy to Help!!