WHAT'S IN THIS CHAPTER?
Social computing refers to the use of technology that allows people to connect with each other. Examples include blogs with reader comments, wikis, and social networks on Twitter, Facebook, and LinkedIn. In addition, there are new rating applications, web applications, and social technologies being developed, allowing users to connect to and benefit from the strength and knowledge of a community.
Today, your business users are more socially aware, and social applications can be easily adopted. One of the reasons for the quick adoption of SharePoint Portal Server 2003 and Microsoft Office SharePoint Server 2007 was that people needed to connect as a group to collaborate efficiently. When the 2003 version of the product was released, users had fast PCs, quick Internet connections, and the software tools needed to be productive as individuals. The next logical step was learning to use software and creating new applications to also be productive as groups and organizations.
Microsoft has been experimenting with social technology since before the term “social computing” was adopted to bring social concepts to the Internet. Several releases of Internet Explorer contained electronic Post-It–style notes, which could be left on websites. As other users who shared the same note server browsed the sites, your notes would be visible and those users could respond with comments of their own.
A decade ago, when team sites were first introduced, the technology allowed users to connect online via a website and collaborate on documents, enter into discussions forums, and communicate with team members. Microsoft Office SharePoint Portal Server 2003 was a collaborative portal solution that connected people, teams, and information.
Enhanced online communication features, including blogs and wikis, were introduced in SharePoint 2007. The marriage of wiki and blog technology with an enterprise content management system was ahead of its time. Since the initial release of SharePoint Portal Server 2007, the adoption of social computing technology has grown significantly, mainly because of the popularity of sites like Facebook, Twitter, and LinkedIn. Concepts like micro-blogging and tagging have proved to be effective ways to stay connected and find information.
SharePoint Server 2010 is designed from the ground up to support a user-centric model, and brings forth new ways to collaborate using both social and enterprise computing tenets. Traditionally, enterprise software defines a user as an identity, which can be assigned access and privileges to data and applications. This is not the case with SharePoint 2010. The product aligns software and services in such a way that the user is at the center of the experience, allowing a mix of social and enterprise computing.
Social networking tools are now first-class citizens in SharePoint; an example is the enhanced Content tab in My Sites. Having the ability to add many types of enterprise content to your My Site allows you to navigate content based on a person and social properties, rather than based on a folder or site hierarchy. Other examples include social tagging, ratings, networks, activity feeds, and the new organization browser. But the main feature is the improvement in the personal (self) view of the My Site. The My Site is now a personal portal for users to consume information from colleagues and those with the same interests.
The people-centric model in SharePoint 2010 begins with the user profile store, formally named the User Profile Service Application (UPA). The core of any social application is the user profile. User profiles allow searching for and connecting to colleagues, in addition to leveraging existing organizational relationships and knowledge. The more you know about your users, the more (cool) things you can do with your software. Of course, today this includes enabling the types of social computing features and social connections users have embraced using the Internet.
You manage user profiles, connections to directories, imports, and settings using the UPA as shown in Figure 5-1. Like many of the services available in SharePoint, the architecture uses a service model. A farm administrator must grant you permissions before you can access the UPA through Central Administration (CA).
As a developer, it is important to understand how user profiles are created, modified, and managed using CA, as well as the object model. All the information SharePoint stores to track users, tags, ratings, and other social data is stored in the user profile and social database. This information is managed using UPA and is exposed to you through the Microsoft.Office.Server.UserProfiles namespace.
Using the PowerShell command prompt, enter the following:
$app_UPA = New-SPProfileServiceApplication -Name UPA -PartitionMode -ApplicationPool $appPool
To provision the UPA on your development server, you need to have the required permission levels. Use the following list to avoid issues with services not starting or synchronization failures. These account settings should not be used in a production environment.
Once the UPA is created, you can use the object model to create profiles. Listing 5-1 illustrates using the UserProfileManager class to create a new profile.
LISTING 5-1: Create a User Profile Using the Object Model
public void CreateUserProfile() { //We have to get current context of the service application strUrl = “http://site”; SPSite site = new SPSite(strUrl); SPServiceContext serviceContext = SPServiceContext.GetContext(site); //UserProfileManager class contains members for profiles UserProfileManager upmanager = new UserProfileManager(serviceContext); //create a new user profile string strAccount = “domain\user”; if (lupmanager.UserExists(strAccount)) upmanager.CreateUserProfile(strAccount); }
The UPA administration screen in CA is divided into four sections. The functionality found in each section is outlined next.
After your farm administrator has created a User Profile Service Application, a designated administrator of the UPA can manage the synchronization process. After synchronization, you can use the user profile and social data from your applications with the object model and web services.
As a developer, you should note that properties can be configured to write back to the synchronization source. This is a big change from previous versions, where the profile synchronization was a one-way import and never updated the source directory. The user profile store has properties that, by default, are mapped to Active Directory and imported during synchronization. You can create custom properties in SharePoint and then map the properties to attributes in Active Directory. Table 5-1 lists the properties that are mapped to Active Directory attributes by default.
ACTIVE DIRECTORY ATTRIBUTE | USER PROFILE STORE PROPERTY |
<dn> | SPS-DistinguishedName |
objectSid | SID |
Manager | Manager |
displayName | PreferredName |
givenName | FirstName |
Sn | LastName |
PhoneticDisplayName | PhoneticDisplayName |
PhoneticFirstName | PhoneticFirstName |
PhoneticLastName | PhoneticLastName |
telephoneNumber | WorkPhone |
WorkEmail | |
physicalDeliveryOfficeName | Office |
Title | Title |
Department | Department |
sAMAccontName | UserName |
wWWHomePage | PublicSiteRedirect |
SIP Address | proxyAddresses |
Source: Microsoft TechNet
A subtype is a type of user. SharePoint 2010 allows you to define different types of users. Examples include contractors and consultants. These different types of users may have different properties associated with them. Subtypes help you resolve the issues that arise because you need to tag different types of users with different properties. After a subtype is created, you can create new profile properties that are targeted at these types of users. User profiles can be filtered based on subtypes. These subtype features are new in SharePoint 2010 (see Figure 5-3).
Developers can use the object model to create, modify, and delete user profiles. Using the object model, properties can be added and modified as well. When you use the object model in Visual Studio, you must add references to a new assembly found in the ISAPI directory under the SharePoint root. The name of the new assembly is Microsoft.Office.Server.UserProfiles; Table 5-2 lists the commonly used namespaces.
Once the reference is added, you will have access to the following namespaces from your code:
Source: SharePoint Server SDK, MSDN
The following code demonstrates how you can use the object model and namespaces in Table 5-2 to update properties of an existing profile. You will set references previously defined. The output is depicted in Figure 5-4.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint; using Microsoft.Office.Server.UserProfiles; using Microsoft.Office.Server; namespace UserProfileStoreOM { class Program { static void Main(string[] args) { using (SPSite site = new SPSite(“http://belize:777”)) { //Get service context SPServiceContext context = SPServiceContext.GetContext(site); UserProfileManager //Get profile uprofileManager = newUserProfileManager(context); string strAccount = “sharepoint\administrator”; UserProfile up = uprofileManager.GetUserProfile(strAccount) //Update values up[PropertyConstants.Office].Value = “NYC”; up[PropertyConstants.Manager].Value = “SharePoint\Ebryce”; up[PropertyConstants.CellPhone].Value = “333-333-3333”; up.Commit(); Console.WriteLine(“Office has been updated to: ” + up[PropertyConstants.Office].Value); Console.WriteLine(“Manager has been updated to: ” + up[PropertyConstants.Manager].Value); Console.WriteLine(“Cell Phone has been updated to: ” + up[PropertyConstants.CellPhone].Value); site.Dispose(); } Console.Read(); } } }
The following section illustrates how you can begin to leverage the user profile store using web parts and web services. A web part project will be created using Visual Studio. The web part will use the object model to retrieve user profile property names and display names. This technique can be used to update or control user properties. To learn more about web part development and deployment, refer to the section on web parts in Chapter 2.
To set up the project, you need to create a blank team site that can be used for debugging. Next, create a blank SharePoint 2010 project using C# and name the project SocialWebParts. When starting Visual Studio, run the application as administrator by right-clicking the Start menu shortcut and select the Run as Administrator option. When the SharePoint Customization Wizard prompts you for a debugging site, enter the URL of the blank debugging site previously created. Be sure to select the .NET Framework 3.5 and the Deploy as a Full-Trust Solution option when prompted.
Use the following steps to create a visual web part project that consumes the user profile web service.
<?xml version=“1.0” encoding=“utf-8”?> <webParts> <webPart xmlns=“http://schemas.microsoft.com/WebPart/v3”> <metaData> <type name=“SocialWebParts.UserProfileData.UserProfileData, $SharePoint.Project.AssemblyFullName$” /> <importErrorMessage>$Resources:core,ImportErrorMessage;</ importErrorMessage> </metaData> <data> <properties> <property name=“Title” type=“string”>User Profile Data Web Part</ property> <property name=“Description” type=“string”> This web part demonstrates consuming data from userprofile.asmx</property> </properties> </data> </webPart> </webParts>
<?xml version=“1.0” encoding=“utf-8”?> <Elements xmlns=“http://schemas.microsoft.com/sharepoint/” > <Module Name=“UserProfileData” List=“113” Url=“_catalogs/wp”> <File Path=“UserProfileDataUserProfileData.webpart” Url=“SocialWebParts_UserProfileData.webpart” Type=“GhostableInLibrary” > <Property Name=“Social web Parts” Value=“Custom” /> </File> </Module> </Elements>
<%@ Assembly Name=“$SharePoint.Project.AssemblyFullName$” %> <%@ Assembly Name=“Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %> <%@ Register Tagprefix=“SharePoint” Namespace=“Microsoft.SharePoint. WebControls” Assembly=“Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %> <%@ Register Tagprefix=“Utilities” Namespace=“Microsoft.SharePoint.Utilities” Assembly=“Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %> <%@ Register Tagprefix=“asp” Namespace=“System.Web.UI” Assembly=“System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35” %> <%@ Import Namespace=“Microsoft.SharePoint” %> <%@ Register Tagprefix=“WebPartPages” Namespace=“Microsoft.SharePoint.WebPartPages” Assembly=“Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %> <%@ Control Language=“C#” AutoEventWireup=“true” CodeBehind= “UserProfileDataUserControl.ascx.cs” Inherits= “SocialWebParts.UserProfileData.UserProfileDataUserControl” %> <asp:GridView ID=“GridView1” runat=“server” AutoGenerateColumns=“false”> <Columns> <asp:BoundField DataField=“Key”/> <asp:BoundField DataField=“Value”/> </Columns> </asp:GridView>
using System; using System.Collections.Generic; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using Microsoft.Office.Server; using Microsoft.Office.Server.Administration; using Microsoft.Office.Server.UserProfiles; using Microsoft.SharePoint; namespace SocialWebParts.UserProfileData { public partial class UserProfileDataUserControl : UserControl { protected void Page_Load(object sender, EventArgs e) { } protected override void OnPreRender(EventArgs e) { using (SPSite site = new SPSite(“http://BELIZE:333”)) { SPServiceContext context = SPServiceContext.GetContext(site); UserProfileManager m_mngr = new UserProfileManager(context); //Get the properties PropertyCollection props = m_mngr.Properties; //Create a Dictionary to store property data. Dictionary<string, string> UserProps = new Dictionary<string, string>(); foreach (Property prop in props) { UserProps.Add(prop.Name, prop.DisplayName); } //Bind the Dictionary to a GridView control. GridView1.DataSource = UserProps; GridView1.Columns[0].HeaderText = “Property Name”; GridView1.Columns[1].HeaderText = “Display Name”; GridView1.DataBind(); } } } }
Now it is time to add an instance of the web part to the debugging site you created earlier. Navigate to the home page, default.aspx, of the debugging site. Click the Edit tab on the Ribbon at the top of the page and then select the command from the Edit Page button. Make sure that a Web Part Zone is selected so that the contextual Page Tools Ribbon tab is displayed. Click the Insert tab on the Ribbon and click the Web Part button. Add the User Profile Data Web Part instance to the page. The web part should look the one shown in Figure 5-5.
In addition to using the object model to create and modify user profiles, you can use the userprofile.asmx web service. Listing 5-2 shows how to retrieve memberships for a user.
LISTING 5-2: Program.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using GetMembershipData.WSUserProf; namespace GetMembershipData { class Program { static void Main(string[] args) { WSUserProf.UserProfileService myUserProfServ = new WSUserProf.UserProfileService(); myUserProfServ.Credentials = System.Net.CredentialCache.DefaultCredentials; GetMembershipData.WSUserProf.MembershipData[] memberships = myUserProfServ.GetUserMemberships(“domainname\username”); for (int i = 0; i < memberships.Length; i++) { Console.WriteLine(memberships[i].DisplayName); } Console.Read(); } } }
Many of the social computing features in SharePoint are accessed and managed using My Sites. Since their introduction in SharePoint Portal 2003, My Sites have been enhanced to become the social networking hub for people in organizations. A My Site is a personal site that provides people with a comprehensive set of social computing features. In addition, My Sites contain personal information about your users as well as personal and public views of information, documents, and other content. My Sites host personal blogs, lists, and web parts. You can add colleagues and organize them into logical groupings. By using activity feeds, you can keep track of the activities that you or your colleagues create.
There are several significant additions to My Sites in the new release of SharePoint. These additions include a My Networks page for managing colleagues, interests, and newsfeed settings; a My Content page for managing documents and photos; and a My Profile page for managing things like user profile information and social tags and notes.
Other enhancements you will notice in the new My Sites include the new Fluent UI and user profile. My Sites have been designed to give you quick access to your content, profile, and social network. You can still customize, target, and personalize pages to the needs of different roles and users in your organization. The activity feed helps people keep track of their interests and the activities of colleagues.
A My Site is divided into three sections using tabs—My Network, My Content, and My Profile. A My Site with tabs, newsfeed, and activity preferences is illustrated in Figures 5-6 and 5-7.
In addition to the three tabs at the top of My Site, the following six tabs are used to navigate personal and social data:
A My Site can be provisioned using the object model, as shown in Listing 5-3.
LISTING 5-3: Using the Object Model to Create a My Site
public void CreateMYSite() { SPServiceContext serviceContext = SPServiceContext.Current; UserProfileManager up = new UserProfileManager(serviceContext); string sAccount = “domain\user”; UserProfile uprof = up.GetUserProfile(sAccount); uprof.CreatePersonalSite(); SPSite newmysite = uprof.PersonalSite; }
The Microsoft.Office.server.SocialData namespace contains classes that are used to access social data. The following classes are defined in the SharePoint developers SDK, and updated members and descriptions can be found on the MSDN website.
Source: MSDN SharePoint SDK
SharePoint has several web services that can be used to access data in the user profile and social database. The web services provide a convenient way to integrate existing applications with SharePoint, as your code does not need to execute on the SharePoint server. The web services are located in the ISAPI directory found in the SharePoint root. References can be added using the _vti_bin mapped path from Visual Studio.
For example, if you had an existing web application on a server named Belize using port 777, the URL used to locate the service would be http://belize:777/_vti_bin/socialdataservice.asmx. You can enter the URL into your browser and see the members of the web service, as shown in Figure 5-8.
The Social Data web service is an interface to the social data stored in SharePoint. As you explore all the methods available in the web service, you will see there is a lot of functionality exposed. An example of this functionality is shown in Listing 5-4. The web service is used to retrieve ratings for a URL, which can represent a page or a document.
LISTING 5-4: Using SocialdataService.asmx to Retrieve Ratings
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; using SocialWebService.ServiceReferencel; namespace SocialWebService { class Program { static void Main(string[] args) { string GetRatingForThisURL = “http://belize:333/Pages/Home.aspx”; ServiceReferencel.SocialDataService mySocialDataService = new ServiceReference1.SocialDataService(); mySocialDataService.Credentials = System.Net.CredentialCache.DefaultCredentials; mySocialDataService.Url = “http://localhost:777/_vti_bin/socialdataservice.asmx”; SocialRatingDetail details = mySocialDataService.GetRatingOnUrl(GetRatingForThisURL); Console.Write(“The rating for ” + GetRatingForThisURL + “ is ” + details.Rating.ToString()); Console.Read(); } } }
Twitter and Facebook's status updates have made the concept of micro-blogging popular. SharePoint implements this capability using status updates, which can be updated by each user. As you browse content and apply tags and notes, your activity feed can be updated with the tag and note data. One business use of the activity feed is to allow other community members to keep track of work in progress and provide presence awareness. Presence awareness allows you to determine where your colleagues are at any given time. An example is an instant message application that signals when users are online, offline, or available via mobile device. You can build a vast array of applications using social computing technologies with the classes defined in Table 5-3. The documentation and samples in the SDK will be extended when SharePoint is released.
The act of tagging content is the assignment of metadata or categories to content. There are two types of tagging: social tagging and structured tagging. Structured tagging refers to content and adds metadata to content to describe what it is, what it contains, or what it does. Social tagging is related to a person and describes the person, such as what they do, which projects they work on, or what skills they have.
You can also tag and create notes on external sites. All of the tag, notes, and rating data is stored in the social database and can be accessed from your My Site or programmatically using the object model. A farm administrator can manage tags using the UPA, as shown in Figure 5-9. The aggregation of tags and notes in the activity feed might prove useful when your users are working with many pages, lists, and documents throughout many sites.
Source: SharePoint Product Team Slide
Each user within your organization can have a personal blog linked to his or her My Site, making it easy for other people to find. New blog posts are added to the Recent Activity section of the user's My Site home page. You can create blog sites as standalone sites. When a blog site is provisioned, the configuration used is determined by the underlying site definition. The default site definition can be found in the SharePoint root under the Site Templates folder.
You will find it refreshing to develop and extend the functionality of your blog using SharePoint Designer. Simply browse to your blog site and select Edit with SharePoint Designer from the Site Actions menu. Working with the blog, lists, and web parts in SharePoint Designer is simple (see Figure 5-10).
Like any other SharePoint site, a blog site can be branded using Master Pages, cascading style sheets (CSS), and SharePoint Designer. In addition, you can save an existing blog site as a web template, import it into Visual Studio, and customize the site definition. The customized site definition can be deployed to the SharePoint root as a new site definition and used when your blog sites are provisioned. As with any other site definition, you can staple features to the custom blog definition to add functionality. The onet.xml file shown in Listing 5-5 can be customized to change the configuration of blog sites created using the custom site definition.
LISTING 5-5: Adding Lists and Web Parts to the onet.xml file Using Visual Studio
<View List=“303” BaseViewID=“0” WebPartZoneID=“BlogNavigator” WebPartOrder=“1”> <![CDATA[ <webParts> <webPart xmlsn=“http://schemas.microsoft.com/WebPart/v3”> <metaData> <type name= “Microsoft.SharePoint.WebPartPages.XsltListViewWebPart,Microsoft.SharePoint,Version =14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c” /> <importErrorMessage>Cannot import this Web Part.</importErrorMessage> </metaData> <data> <properties> <property name=“AllowConnect” type=“bool”>True</property> <property name=“ChromeType” type=“chrometype”>None</property> </properties> </data> </webPart> </webParts> ]]></View> <AllUsersWebPart List=“301” WebPartZoneID=“BlogNavigator” WebPartOrder=“2”> <![CDATA[ <WebPart xmlns=“http://schemas.microsoft.com/WebPart/v2”> <Assembly>Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly> <TypeName>Microsoft.SharePoint.WebPartPages. BlogMonthQuickLaunch </TypeName> <Title>$Resources:core,months_schema_blg_title;</Title> <Description>$Resources:core,blog_month_quick_launch; </Description> <FrameType>None</FrameType> <FrameState>Normal</FrameState> <IsVisible>true</IsVisible> </WebPart> ]]></AllUsersWebPart> <AllUsersWebPart List=“301” WebPartZoneID=“Right” WebPartOrder=“1”> <![CDATA[ <WebPart xmlns=“http://schemas.microsoft.com/WebPart/v2”> <Assembly>Microsoft.SharePoint, Version=14.0.0.0, Culture= neutral, PublicKeyToken=71e9bce111e9429c</Assembly> <TypeName>Microsoft.SharePoint.WebPartPages.BlogAdminWebPart </TypeName> <Title>$Resources:core,adminlinks_schema_blg_title;</Title> <Description>$Resources:core,blog_admin_links;</Description> <FrameType>Default</FrameType> <FrameState>Normal</FrameState> <IsVisible>true</IsVisible> </WebPart> ]]></AllUsersWebPart> </File>
The Collaboration Portal in SharePoint 2007 has been deprecated and the functionality replaced with the Enterprise Wiki (EW) site definition, shown in Figure 5-11. The EW is a publishing site with all of the publishing features enabled at the site collection level. Wiki pages are stored in a pages library and can benefit from output caching and other Web Content Management features enabled for the page library.
When you create an EW you must first create and configure the following:
The Wiki page content type has a Wiki Category column, which you use to categorize individual wiki pages. The category column is a managed metadata field that allows the categories to be managed using a term set in the MMS term store. When you edit a wiki page, you have the option to select a category for the page based on the defined term set linked to the category column.
When editing a wiki page, you can add web parts. Unlike web parts added to web part pages, the wiki web parts do not have to be added to a Web Part zone. Web parts are added to wiki pages using the same Ribbon you use when adding them to any other page. The wiki page has a hidden Web Part zone named WP Zone, which allows for the inline adding of web parts. Another nice feature is that, when a wiki page version is restored, the web part properties are also restored.
The WikiEditPage class can be found in the Microsoft.SharePoint.WebPartPages namespace. The class includes a method InsertWebPartIntoWikiPage, which handles adding your web parts to the wiki pages. Additional members can be used to extend the wiki page publishing infrastructure.
This chapter covered the new people-centric features available to you as you deploy and develop solutions using SharePoint. Microsoft is investing a lot in the social and community capabilities of SharePoint. SharePoint has a vast object model, which can be used by developers to track and modify social data. Understanding the differences between business-centric enterprise computing and social computing is important as you deploy people-centric solutions using SharePoint. Tags, ratings, and notes are ubiquitous in SharePoint and allow you to share tacit and structured social information with your organization. The keystone to any social application is the user profile store; remember, the more you know about your users, the more great things you can do with your software.