SharePoint Zip Logo A Black Blade Associates blog. Struggling with SharePoint? We can help.


Blog moved: This blog has moved to http://thingsthatshouldbeeasy.wordpress.com. Go there now to see the new posts.


Monday, March 22, 2010

Getting Started with SharePoint 2010

I often get asked the question, “How do I as a SharePoint 2007 professional start getting expertise in SharePoint 2010? My organization is not planning to move to SharePoint 2010 because its customers still plan to be on SharePoint 2007 for some time .”

Many SharePoint professionals are in this boat, as are many organizations. The wide success of SharePoint 2007 is one of the biggest impediments to organizations’ and professionals’ migration to SharePoint 2010. So, I will answer your question from those two perspectives: the organization’s and the professional’s.
 

As an organization

We have a SharePoint 2007 infrastructure, which we are planning on upgrading to 2010 with all reasonable haste. We have to test our own customizations as well as some 3rd party tools. All considered, we plan to be on 2010 before the year is out. We will use this for our portal, customer-facing extranet, and public web site. This will let our internal people gain experience with SharePoint 2010 long before we have a customer requirement.

However, most of our customers will be on 2007 for several years. So we will be maintaining a development infrastructure compatible with SharePoint 2007. Among other things, it means not using many of the new .Net Framework 4.0 capabilities and not using the SharePoint 2010 tools in Visual Studio 2010. I will be training our developers to write code that runs on SharePoint 2007 but can still take advantage of SharePoint 2010 if available. I'm speaking on this topic at the SharePoint Evolution Conference this April.

 

As a SharePoint 2007 professional

Start small. Watch SharePoint 2010 web casts, read blog posts, and attend user group and SharePoint Saturday meetings. The goal is get some familiarity with SharePoint 2010 with minimal time, cost, and infrastructure investments.

Once you're ready to go hands on, don't do it alone. Convince your organization that it needs to provision a SharePoint 2010 sandbox. Make things simple: go standalone topology. Tell the decision makers that you and some other colleagues will pick an existing application or piece of functionality and try to create it on SharePoint 2010. You will write about your experience and share with other interested members of your organization. You get SharePoint 2010 experience without personal outlay of funds. The organization gets a group of member gaining steadily increasing expertise in the next version of the platform without a formal outlay of training budget.

You should start today, but you don’t need to become a SharePoint 2010 expert today. Rather, you should focus on gaining incremental 2010 experience over the next 12 – 18 months.

Monday, March 15, 2010

Speaking at SharePoint 2010 Evolution Conference

I’m very excited to be speaking at the SharePoint 2010 Evolution Conference in London this April. I was supposed to speak there last year as well but had a last-minute scheduling conflict. It was definitely my loss. I heard from speakers and attendees alike how good the conference was. There’s no way I’m missing it this year.

My session is DEV104, “Things that Should be Easy in SharePoint Development”. This is a 200-level session targeted at junior to mid-level developers. The goal of the session is to go through several SharePoint programming tasks that one would think would be fairly straight forward but are not. These gotchas can put off new SharePoint developers and cause project delays for even those experienced with the platform.

Here’s the session outline:

  • Querying Data
    What good is putting data into SharePoint if you can’t get it out when and how you need? We’ll look at some troublesome quirks that make it hard to get at the SharePoint information you need.
     
    • Relational Data Queries
    • Date Time Queries
    • Site Context via HTTP
       
  • Workflow
    The SharePoint workflow features are really good. Learn how to deal with the stumbling blocks to making them great. 
     
    • Creating Workflow Tasks
    • Processing Task Changes
    • Working with OOTB task forms
    • Creating Custom Workflow Activities
       
  • User Interface
    The SharePoint user interface framework is highly extensible. Learn how to get the most benefit out of the web part framework.
     
    • AJAX
    • Reusable Dataview Web Parts
    • Web Part Connections with OOTB Web Parts
       
  • Platform
    There are 6 major SharePoint platform versions. Write code that will dynamically detect the SharePoint platform type and version, whether the code is running on the SharePoint farm or remotely.
    Once you can detect on which of the 6 major SharePoint platform versions your code is running, how do you make sure your code will run without error, and without settling for “lowest common denominator” feature set? Of course we’ll want to do it all with a single code base.
     
    • Platform Detection Mechanisms
      • Object Model
      • Registry
      • File System
      • HTTP Code
    • Multi-platform Code
      • Object Model
      • HTTP Code

Join me for in London, UK April 19-21, 2010. This is going to be a great conference. If you can’t make it, don’t worry; I’ll write up blog posts on the more popular topics from my session. Leave a comment on which topic you’d like to see a post.

Thursday, March 04, 2010

How To: Use default SharePoint approve/reject InfoPath task form in custom Visual Studio workflows

I needed to write a customized approval workflow. I know I could use InfoPath to create custom approval task forms, and I saw many posts showing how this is done. But if I could use the SharePoint Approval Workflow task forms, I could save a lot of development time and deployment effort.
This post focuses on how I was able to use the out of the box InfoPath approval approve/reject task forms forms in my custom Visual Studio SharePoint workflow.If you’re looking for a general how-to post on creating SharePoint workflows with Visual Studio, this is not the post for you. I would instead point you to Serge Luca’s excellent 20-part series on creating SharePoint workflows with Visual Studio.

Creating the task

Here’s the skinny on what you need to do in order to use the default Microsoft Office SharePoint Server 2007 (MOSS) approve/reject InfoPath form in a custom Visual Studio workflow.
1. Create a SharePoint workflow project
There are many ways to do this, so I won’t go into details here. My personal favorite way is by using the WSP Builder Visual Studio workflow template project. Just make sure that your workflow class inherits from System.Workflow.Activities.SequentialWorkflowActivity or from System.Workflow.Activities.StateMachineWorkflowActivity.


2. Set the TaskListContentTypeId attribute
Edit the elements.xml file in your workflow feature definition. Set the TaskListContentTypeId attribute value to use the MOSS workflow task content type id:
<Elements> 
<Workflow
Name="MyWorkflow" 
Description="This is my custom workflow."        TaskListContentTypeId="0x01080100C9C9515DE4E24001905074F980F93160" 
        ></Workflow></Elements>
3. Add the Task_FormURN and ExtendedStatusColumnValues elements
Continue to edit the elements.xml file in your workflow feature definition. Add the following MetaData element under the Workflow element:
<Elements> 
<Workflow> 
        <MetaData> 
<Task0_FormURN>urn:schemas-microsoft-com:office:infopath:workflow:ReviewRouting-Review:$Subst:LCID;</Task0_FormURN> 
<Task1_FormURN>urn:schemas-microsoft-com:office:infopath:workflow:ReviewRouting-Review:$Subst:LCID;</Task1_FormURN> 
<Task2_FormURN>urn:schemas-microsoft-com:office:infopath:workflow:ReviewRouting-Review:$Subst:LCID;</Task2_FormURN> 

<ExtendedStatusColumnValues> 
<StatusColumnValue>$Resources:ReviewFeedback_CanceledStatus</StatusColumnValue> 
<StatusColumnValue>$Resources:ReviewFeedback_ApprovedStatus</StatusColumnValue> 
<StatusColumnValue>$Resources:ReviewFeedback_RejectedStatus</StatusColumnValue> 
</ExtendedStatusColumnValues> 
</MetaData> 
</Workflow></Elements>
4. Add a CreateTask activity to your workflow
Add a CreateTask activity to your workflow. Make sure to set the TaskType property on the TaskProperties of the CreateTask activity to 1. This will tell the workflow runtime to create the task using the Form Urn corresponding to the inner text in the Task1_FormURN element. The CreateTask activity’s MethodInvoking event is a good place to set the property.

private void createTask1_MethodInvoking(object sender, EventArgs e)
{
//initialize task infrastructure data
this.createTask1_TaskId1 = Guid.NewGuid();
this.createTask1_TaskProperties1 = new Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties();
    this.createTask1_TaskProperties1.TaskType = 1;
 
//set task remaining properties
//...
}

Processing a workflow task

Now that you’ve created a workflow task that uses the default approval form, you will want to your workflow to do something useful when a user approves or rejects the task. Here is how to detect when a user approves or rejects the workflow task.

5. Detect task change with OnTaskChanged
This is fairly straight forward: add an OnTaskChanged activity to your workflow. Set the task ID and correlation token to correspond to the ones used when creating the task in the previous section. See Serge Luca’s SharePoint workflow series for details.

6. Task approved or rejected
Here’s the interesting part. Whether a user approves, rejects, reassigns, or requests a change in the task form, the task is always marked as Complete. The actual value that corresponds to what the user selected is stored in the TaskStatus in the ExtendedProperties collection of the SPWorkflowTaskProperties class. The following is a table that correlates the user’s approval action to the value of the TaskStatus extended property:

User ActionTaskStatus Value
Approve“#”
Reject“@”
Cancel[no change]


Here’s a sample helper method that checks whether a particular workflow task was approved:

public static bool IsTaskApproved(SPWorkflowTaskProperties TaskProperties)
{
return TaskProperties.ExtendedProperties["TaskStatus"] != null
&& TaskProperties.ExtendedProperties["TaskStatus"] as string == "#";
}

Anything else?

That’s it. There is surprisingly little work involved in using the default MOSS approvals forms in your own custom SharePoint Visual Studio workflows, once you know what to look for that is. I’d like to wrap us this post with the benefits to this approach and a few things you should keep in mind when working with the default workflow forms.

Some benefits to this approach
Here are just some of the benefits you get when you reuse the existing MOSS approval task forms rather than creating your own customs InfoPath task forms:

  1. No InfoPath forms development
  2. No InfoPath forms deployment
  3. Out of the box user interface for:
    1. Approve
    2. Reject
    3. Cancel
    4. Reassign Task
    5. Request a change
    6. Instructions to approver
    7. Capture approver comments
  4. Out of the box multi-language user interface with appropriate MOSS language packs. Notice the references to “$Resources:”.
A few things you should know
  • Any action in default task forms except Cancel marks the task “Complete”. Your workflow must then create a new task with the desired action from the completed task. For example: If a user re-assigns the task to a new user, the task for the user is marked complete. Your workflow must create a new task and assign it to the new user.
  • The MOSS task forms derive most of their data from fields in the ExtendedProperties of the task, not the main task properties.