Skip to main content

Get Sum of Columns in a SharePoint list (Threshold edition)

It is a known fact that once the treshold limit is reached in SP, everything seems frozen.  At this point you have some options. Increase the limit using powershell or from the Central Admin OR Index the columns that you will like to operate on and create views based on those.

However programmatically if you want to sum a list that has reached its threshold.  You can do so in batches as hown below:

        protected void GetSummary(out long ideas, out long votes, out long comments, out long transform)
        {
            long ideasum = 0;
            long columntoSum = 0;
            long commentSum = 0;
            long transformSum = 0;
 
            SPSite site = SPContext.Current.Site;
            SPWeb web = site.RootWeb;
            SPList ideaList = web.Lists.TryGetList("ListName");
//Get the maximum number of items in the list
double idealimit = MaxId(); //this function is explained in one of my posts(http://www.blogger.com/blogger.g?blogID=2123753259723977594#editor/target=post;postID=9105210765468295611;onPublishedMenu=allposts;onClosedMenu=allposts;postNum=1;src=postname)
 
            double noOfTimes = Math.Ceiling(idealimit / 5000);
 
            int start = 0;
            int end = 0;
            for (int i = 0; i < noOfTimes; i++)
            {
                start = i * 5000;
                end = start + 5000;
                SPQuery query = new SPQuery();
                query.RowLimit = 5000;
                query.Query = string.Format(@"{0}{1}Active", start, end);
 
                SPListItemCollection items = ideaList.GetItems(query);
                DataTable dt = null;
                dt = items.GetDataTable();
                if ((null != dt) && (dt.Rows.Count > 0))
                {
                    string sqlFilter = string.Format("IdeaStatus LIKE '%{0}%'""Active");
                    DataRow[] foundRows;
                    foundRows = dt.Select(sqlFilter);
                    if (foundRows.Count() > 0)
                    {
                        foreach (DataRow item in foundRows)
                        {
                            columnSum += Convert.ToInt64(item["columntoSum"]);
                        }
                    }
                }
            }
            comments = commentSum;
        }

Comments

Popular posts from this blog

Event Date Function

  Date.toISOFormat = function (date, ignoreTime) {      /// <summary>Date object static method to format a date to date ISO string - YYYY-MM-DDThh:mm:ssZ</summary>      /// <param name="date" type="Date" mayBeNull="false" optional="false"></param>      /// <param name="ignoreTime" type="Boolean" mayBeNull="false" optional="true"></param>      /// <returns type="String">A string representing ISO format for specied date</returns>        // If not specified, time is ignored      var ignoreTime = ignoreTime || {};        function pad(number) {          // Add leading 0 if number is less then 10 (enclosed method)          var r = String(number);          if (r.length ==...

The _spPageContextInfo

I f you are creating a SharePoint app using JavaScript and the Client side object model you need this friendly object. In the development of an app, you would require some basic properties- SharePoint as a framework provides these with the  _spPageContextInfo  object. _  spPageContextInfo  will provide these below properties:  webServerRelativeUrl  webAbsoluteUrl siteAbsoluteUrl serverRequestPath layoutsUrl webTitle webTemplate tenantAppVersion isAppWeb webLogoUrl webLanguage currentLanguage currentUICultureName currentCultureName env nid fid clientServerTimeDelta updateFormDigestPageLoaded siteClientTag crossDomainPhotosEnabled webUIVersion webPermMasks pagePersonalizationScope userId userLoginName systemUserKey alertsEnabled siteServerRelativeUrl allowSilverlightPrompt themedCssFolderUrl themedImageFileNames

PublishingAssociatedContentType

The Content Type to be associated with a page layout is indicated by the 'PublishingAssociatedContentType'. In the actual sense it means a binding setting between the Page Layout and the content type. If you fail to provide one, the SharePoint framework will make use of the Page Content type. The format of the binding is: ';# e.g. ';#ContentPage;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900470b13dd348649d08f9e5151501df9a4000dbd46dad8d045f98c83ad983b66d3f2;#'. where Content Type name: ContentPage Content Type ID: 0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900470b13dd348649d08f9e5151501df9a4000dbd46dad8d045f98c83ad983b66d3f2 respectively. QED