Wednesday, January 27, 2010

SharePoint 2010 Social Networking Part 1: Setting the user My Site status message programmatically

SharePoint 2010 comes along with a wide range of the social feature like note boards, rating, bookmarking, tagging etc. I’ll be doing a series of blog posts to share some code snippets for managing these cool features programmatically.

One of the interesting social feature is setting the My Site status message which depicts the mood of the user. In the part 1 of this series I’ll demonstrate a small code snippet to set the My Site status message programmatically.

So we’ll start by adding the required assembly references to our console application:

Microsoft.SharePoint.dll
Microsoft.Office.Server.dll
Microsoft.Office.Server.UserProfiles.dll
System.Web

Followed by the following namespace decelerations:

using Microsoft.SharePoint;
using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;

Now one wearied issue that the users with Visual Studio 2010 beta would notice here is as soon as you compile the solution, you’ll probably notice this error followed by a warning:

image

I wasted a whole day fighting this issue until I found this post by Chris where he points out it as a development issue in VS2010 beta build.

So essentially we would need to add the reference to System.Web.DataVisualization.dll into our project and we are good to go.

Now we’ll add the method as shown below to our application:

  SetStatusMessage

Essentially here we are stating by instantiating the SPSite object for a SharePoint site URL (http://intranet.contoso.com). Then we are creating an object of SPServiceContext class which would enable us make a call to the user profile service application.

Next is to instantiate the UserProfileManager class object for accessing the user profiles and their data stored in the user profile database. The GetUserProfile method of the UserProfileManager class accepts several overloads and returns the user profile for the specified user (in our case the administrator).

Now among the several OOB user profile properties configured on the server, the property SPS-StatusNotes is the one which we are looking for. Setting the value of this property with a string value would set the the status message for the user. The final step is to commit the changes by calling the Commit method.

Now call this method and pass a string message “Status set from code.”. Finally executing our console app would result in setting the status message for administrator as shown in the image below.

 My Site status.

Tuesday, January 12, 2010

SharePoint WCM Feature Generator

From my experiences on of SharePoint WCM projects I did so far, I came across certain repetitive & time-consuming development tasks. Some of them are listed below:

1. Creating Site Definition

2. Features

· Site Columns- Columns used in lists/libraries/page layouts.

· Content Types- Lists/Page Layout content types.

· Content Type Associations- Association of Content Types with the SharePoint list.

· Master Pages and Page Layouts- Provisioning master pages and layouts on SharePoint master pages library.

· Provision Files- Provision image, CSS, XAPS and documents on specified SharePoint library.

· Feature Staplers- Auto activation of features based on site creation.

3. Feature Receivers

4. Custom Controls

The image below illustrates the Visual Studio 2005/2008 solution for a typical SharePoint WCM project.

VSSolution

Keeping the same thought in mind, I have developed a utility SharePoint WCM Feature Generator to automate the feature creation for some of the fundamental WCM components in SharePoint like Site Columns, Content Types, Content Type Associations, Provisioning etc (indicated by green callout).

SharePoint WCM Feature Generator

Also this tool well integrate with Visual Studio to make things even simpler.

The SharePoint WCM Feature Generator is targeted for both Microsoft Office SharePoint Server 2007 and SharePoint 2010.

The tool can be downloaded from here: SharePoint WCM Feature Generator.exe

The user guide can be downloaded from here: SharePoint WCM Feature Generator User Guide