Configuring a Community with the App Model

Configuring a Community with the App Model header image

With SharePoint 2013 Microsoft introduced a new template type for Communities. With this template anyone can create a place to discuss about a project or topic. As a community focuses on members, discussions and reputation there are some extra settings that can be done once a community site is created. From the Site Settings page there are a few links that can be found under Community Administration. From the Community Administration you can select the Community Settings for specific settings for the community, and the Reputation Settings to configure the reputation scores that you would like.

So in order to leverage the app model for structured and repeatable deployments some work has to be done to set these settings as well. Creating a community will be the same as creating any sub site.

Web web = clientContext.Web;

Web communityWeb = web.Webs.Add(new WebCreationInformation {
    Title = "Community",
    Url = "Community",
    Language = 1033,
    UseSamePermissionsAsParentSite = true,
    WebTemplate = "COMMUNITY#0"
});

clientContext.ExecuteQuery();

Community Settings

From the Community Settings page there are three options available:

  • Established Date
  • Auto-approval for permission requests
  • Reporting of offensive content

Currently there is no API available to set these settings either through the App Model or with the FTC model so you have to set these settings in the property bag and execute any other logic yourself. For the first two options this is fairly easy as it is just setting the desired web properties. For retrieving the correct time we can use the LocalTimeToUTC but we have to do a ExecuteQuery since that is a ClientResult. For the Auto-approval for permission requests it is just a true / false flag that can be set.

var localTime = communityWeb.RegionalSettings.TimeZone.LocalTimeToUTC(DateTime.Today.AddMonths(-1));
clientContext.ExecuteQuery();

var props = communityWeb.AllProperties;
props["vti_CommunityEstablishedDate"] = localTime.Value;
props["vti_CommunityEnableAutoApproval"] = true.ToString();
communityWeb.Update();
clientContext.ExecuteQuery();

If you are determined to set the Reporting of offensive content as well, you can use the vti_CommunityEnableReportAbuse property but you will also have to take care of all of the following steps:

  • Add the Abuse Report fields on the discussion list
  • The Abuse Report fields to the standard views
  • Create the Abuse Report view
  • Add the Abuse Report custom action

Reputation Settings

As for setting reputations there is no public API available yet either, however setting it can be done through the use of properties on the RootFolder of the discussion list. These settings are done fairly easy, as out of the box the reputation settings are enabled. So in order to change them you have a few options. You can set the AchievementPointsEnabled to false if you do not want to work with them. If you do you can set the AchievementPoints property with the values in the corrected order

  • Creating a new post
  • Replying to a post
  • Member’s post or reply gets liked or receives a rating of 4 or 5 stars
  • Member’s reply gets marked as ‘Best Reply’

And you have the option to set the LevelTresholds to determine when a user should get a certain rank. You can use the Rating_VotingExperience to determine whether you can use Likes or Ratings, and finally if you do not want to see the achievement level as an image you can set the DisplayAchievementAsImage to False and use the Level1Text to Level5Tetxt with the desired labels.

Web communityWeb = clientContext.Site.OpenWeb(site.ServerRelativeUrl + "/Community");
Folder discussionFolder = communityWeb.GetList(site.ServerRelativeUrl + "/Community/Lists/Community Discussion").RootFolder;

var props = discussionFolder.Properties;
props["AchievementPointsEnabled"] = "True";

// New post; Replying Post; Get like or rated; Best reply
props["AchievementPoints"] = "1;5;10;100";

props["LevelThresholds"] = "0;100;250;1000;10000";

props["Ratings_VotingExperience"] = "Likes"; // Ratings

props["DisplayAchievementAsImage"] = "False";
props["Level1Text"] = "Mavention Level 1";
props["Level2Text"] = "Mavention Level 2";
props["Level3Text"] = "Mavention Level 3";
props["Level4Text"] = "Mavention Level 4";
props["Level5Text"] = "Mavention Level 5";

discussionFolder.Update();
clientContext.ExecuteQuery();

Once you have set all the properties you can update the root folder for the changes to be committed.

You can download the Sample App for SharePoint (225KB, ZIP).

Loading comments…