Showing posts with label SharePoint list. Show all posts
Showing posts with label SharePoint list. Show all posts

Monday, December 30, 2013

Indexing SharePoint list columns

We can index the columns in SharePoint to improve the performance. Indexing on the columns enables us to analyze the data quickly for a specific column. We can use filters for indexed to view large number of items to use for sorting, grouping and filtering. We can create the indexes for list and library columns.
For the additional column index, it will take more resources from the database. By adding the indexes we have to columns will be used for view items in SharePoint list.
We add indexes in SharePoint list manually or using SharePoint object model. We can create indexes for SharePoint list/library using following code
To create on Single column (Single Column index)

using(SPSite currentSite=new SPSite(“SiteURL”)
{
                    using(SPWeb currentWeb=CurrentSite.OpenWeb())
                    {
                               SPList currentList=CurrentWeb.Lists[“List Name”];
SPField titleFiled = currentList.Fields["Title"];
titleFiled.Indexed = true;
titleFiled.Update();

currentList.FieldIndexes.Add(titleFiled);
                    }
}

We can create compound index using following code

using(SPSite currentSite=new SPSite(“SiteURL”)
{
                    using(SPWeb currentWeb=CurrentSite.OpenWeb())
                    {
                               SPList currentList=CurrentWeb.Lists[“List Name”];
SPField createdByField = currentList.Fields["Author"];
createdByField.Indexed = true;
createdByField.Update();

SPField createdField = list.Fields["Created"];
createdField.Indexed = true;
createdField.Update();

list.FieldIndexes.Add(createdByField, createdField);
                    }
}

We can create the index only few fields in SharePoint list. It is not possible to create the indexing for all the fields in a list. Here are the list of the fields we can create indexing.