Tuesday, March 15, 2011

SharePoint News Feed Formatting of ActivityEvent

It is quite easy the get the news feed for activities from your colleagues and for your interests and skills in SharePoint 2010. It is not, however, that simple to format each event to display them in your own web-part using the activity feed object model.

Sure, the data of the different activity types are all there in the ActivityEvent object, and you can get the ActivityTemplate based on the ActivityType of the event. But then you need to process the display template tags to merge in the event values or the event XML from TemplateVariable string property using the SimpleTemplateFormat and ActivityTemplateVariable classes. See the Fun and Games with the ActivityEvent post by Toby Statham to get you started.

Luckily, the activity feed is based on the web syndication model, so you can simply create a SyndicationItem object based on the activity event, and it will find and process the activity template for you:

private Panel CreateFeedEventPanel(ActivityEvent activity)
{
    Panel panel = new Panel()
    {
CssClass = "MyProfileActivityFeedEventPanel"
    };
 
    //access the LinkList property in order to populate the ActivityEvent
    List<Link> temp = activity.LinksList;
 
    string picture = activity.Publisher.Picture;
    picture = string.IsNullOrEmpty(picture) ? "/_layouts/images/O14_person_placeHolder_32.png" : picture;
    
    Image publisherImage = new Image()
    {
ImageUrl = picture,
AlternateText = activity.Publisher.Name,
CssClass = "MyProfileActivityFeedEventPublisher"
    };
    panel.Controls.Add(publisherImage);
 
    SyndicationItem syndicationItem = activity.CreateSyndicationItem(_activityManager.ActivityTypes, ContentType.Html);
    panel.Controls.Add(new LiteralControl() { Text = syndicationItem.Summary.Text });
 
    return panel;
}
 
private void PopulateNewsFeedActivityList(bool useTodayOnly)
{
    string url = SPContext.Current.Site.Url;
    using (SPSite site = new SPSite(url))
    {
SPServiceContext context = SPServiceContext.GetContext(site);
UserProfileManager profileManager = new UserProfileManager(context);
SPUser user = SPContext.Current.Web.CurrentUser;
UserProfile userProfile = profileManager.GetUserProfile(user.LoginName);
_activityManager = new ActivityManager(userProfile, context);
 
if (useTodayOnly)
{
    DateTime todayFilter = DateTime.Now.Date;
    _activityList = _activityManager.GetActivitiesForMe(todayFilter);
}
else
{
    _activityList = _activityManager.GetActivitiesForMe(MaxItems);
}
    }
}

The formatted HTML will be the same as rendered by the NewsFeedWebPartBase class, except for the profile picture size and some missing timestamps for some event types. Use Reflector on the news feed web-part base class to see the code for mitigating such details.

The code for getting activity events for a user and other SharePoint 2010 social computing "how-tos" can be found in the User Profiles and Social Data section at MSDN.

Wednesday, February 23, 2011

Help Content Cannot Be Displayed in SharePoint 2010

Today we had a weird error on our SharePoint 2010 production farm: clicking on help got the "help content cannot be displayed" error for all normal sites, even though it worked perfectly well in Central Admin. The same applied to Site Settings>Help Settings for the site-collection, it worked in Central Admin, but not in any other site. In addition, the 'SharePoint Foundation Search' service was running on one WFE server.

First I checked all settings in KB939313 without that fixing the problem, then I checked the log files and found this access denied error for our site's app-pool account:

SqlError: 'The EXECUTE permission was denied on the object 'proc_EnumResourcesAtScope', database 'SharePoint_AdminContent_ABBAef34-7603-4da5-823a-43ee1327ABBA', schema 'dbo'.'

Before embarking on changing any database rights, we decided to test with an English site just in case, as all our custom site definitions are in Norwegian. Lo and behold - help worked for the new team-site; and what's more, suddenly help was working for all our existing Norwegian LCID 1044 sites also. Go figure...

[UPDATE] See the comments for tips on granting execute rights on the sprocs listed in the ULS to fix this problem once and for all - even beyond IISRESET.

Monday, February 21, 2011

Starting Term Store Management in SharePoint 2010

If you can't get any edit or management popup menus such as add term store term group to show in the SharePoint 2010 Managed Metadata Service application Term Store Management Tool, check that:
  • Internet Explorer is started with "Run as administrator"
  • You have added your taxonomy managers to the "Term Store Administrators" for the MMS root node

This is required even if you are an administrator of the MMS application itself and you have full control MMS connection permissions.

So then you're ready to realize your ingenious taxonomy for classifying and organizing your knowledge with managed metadata and content types.

Friday, January 14, 2011

Arctic SharePoint Challenge 2011

The lynx is out of the bag: Get down with Arctic SharePoint Challenge at http://pzl.no/asc2011

Twitter: @spchallenge