5

How to activate the "Like" option programatically on a custom list in SharePoint Online?

3

To add only like feature, It is needed to add two site columns in the list.

Site columns are:

  • LikesCount which GUID ID is 6e4d832b-f610-41a8-b3e0-239608efda41
  • LikedBy which GUID ID is 2cdcd5eb-846d-4f4d-9aaf-73e8e73c7312

Following is the code

using(ClientContext clientContext = new ClientContext(targetSite)) {
    clientContext.Credentials = onlineCredentials;
    Web web = clientContext.Web;
    List list = web.Lists.GetByTitle("List Name");
    clientContext.Load(list);
    clientContext.ExecuteQuery();

    var likeCount = web.AvailableFields.GetById(new Guid("6e4d832b-f610-41a8-b3e0-239608efda41"));
    var likedBy = web.AvailableFields.GetById(new Guid("2cdcd5eb-846d-4f4d-9aaf-73e8e73c7312"));

    clientContext.Load(likeCount, p => p.SchemaXmlWithResourceTokens, p => p.Id, p => p.InternalName, p => p.StaticName);
    clientContext.Load(likedBy, p => p.SchemaXmlWithResourceTokens, p => p.Id, p => p.InternalName, p => p.StaticName);
    clientContext.ExecuteQuery();

    list.Fields.AddFieldAsXml(likeCount.SchemaXmlWithResourceTokens, true, AddFieldOptions.AddFieldInternalNameHint | AddFieldOptions.AddToAllContentTypes);
    list.Fields.AddFieldAsXml(likedBy.SchemaXmlWithResourceTokens, true, AddFieldOptions.AddFieldInternalNameHint | AddFieldOptions.AddToAllContentTypes);

    list.Update();
    clientContext.ExecuteQuery();
}
0

A Microsoft SharePoint Server 2010 farm-level feature called SocialRibbonControl causes the I Like It and Tags & Notes controls to be displayed on the Documents and Items tabs of the ribbon for document libraries and lists, as well as on all browse pages.

These controls enable users to tag and rate items and to leave notes on Web pages, including the users' My Profile pages. By default, the SocialRibbonControl feature is enabled.

Disabling the SocialRibbonControl feature is not the same as removing the Use Social Features permission for a user or group. The ribbon control affects only the display of tabs and browse pages.

You might want to disable the SocialRibbonControl feature if your organization has disabled the Use Social Features permission so users will not see the controls when they cannot use the social features of SharePoint Server 2010.

When this feature is disabled, users will not see the I Like It and Tags & Notes selections on the ribbon or on browse pages.

Consider the following issues if you plan to disable the SocialRibbonControl feature:

The feature cannot be enabled for individual Web applications in a SharePoint farm.

Any associated user data or customizations might be lost, and any active features that depend on this feature might no longer function.

Farm level feature for solical ribbon ocntrol in list and libraries

  • So in regards to this question asking about SP:O, how does this relate to turning on and using the "Like" functionality programmatically? – Jordan Feb 3 '16 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.