Tuesday, May 19, 2015

What's happening webpart is showing incorrect value in community site SharePoint 2013

Introduction

Most of us came across about this issue, which is count of Members, Discussion and Replies. Normally, These values are tracking in properties. In Some cases, It will not update properly. Let see how to update this.


Community site properties 

Open your community site in SharePoint Designer. Click Site options in top ribbon



Then we can able to see the parameters (properties) of site.


We can find the Community_MemberCount there, which is used to keep member's count of community.

Update the properties using Event receiver

We need to update the property when the user has leave from Community Member list. So, I have written the code in Community Member list event receiver to update the property. Members are not deleted from the list. They have changed the flag when user enforced to delete. So we need to code it when ItemUpdated


public override void ItemUpdated(SPItemEventProperties properties)

        {

            var web = properties.Web;

            var currentAllowUnsafeUpdatesVal = web.AllowUnsafeUpdates;
            try
            {
               var membersCountQueryCAML = "<Where><Eq><FieldRef Name='MemberStatusInt' /><Value Type='Integer'>1</Value></Eq></Where>";
            var membersCountQuery = new SPQuery();
            membersCountQuery.Query = membersCountQueryCAML;
            
                var membersCount = membersList.GetItems(membersCountQuery).Count;
                web.AllowUnsafeUpdates = true;
                if (web.AllProperties.ContainsKey("Community_MembersCount"))
                {
                     web.AllProperties["Community_MembersCount"] = membersCount.ToString();
                    web.Update();
                 }
                base.ItemUpdated(properties);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                web.AllowUnsafeUpdates = currentAllowUnsafeUpdatesVal;
            }
        }

Then, deploy / upgrade your solution in your community site. Now Whats happening webpart will give the correct member's count.

Increase the Social Comment Webpart (NoteBoard) item count

Introduction

As all we know, We have Noteboard webpart in SharePoint which is used to comment about particular page. Refer this blog for get intro about it. 

The items count of this webpart is set as 3 by default. We can able to change it as we wish.



        <prfx:SocialCommentWebPart runat="server" ChromeType="TitleOnly" Title="Comments" WebPartPropertyDisplayItems="10" />

Set WebPartPropertyDisplayItems with the count which you want.  That's all Noteboard webpart will display number of items which you gave.