Set List Column Index in SharePoint using CSOM

The example in this topic show how to use CSOM to Set List Column Index in SharePoint

  • using Microsoft.SharePoint.Client;
  • using System.Linq;
  •  
  • // Adding an index to a column increases performance when you use filters.
  • // You can add indexes on up to 20 columns on a list or library.
  • // It's recommended you add indexes to only to the most commonly used columns.
  • // Indexes add overhead to the data.
  •  
  • using (ClientContext clientContext = new ClientContext("http://MyServer/sites/MySiteCollection"))
  • {
  • // clientcontext.Web.Lists.GetById - This option also can be used to get the list using List GUID
  • // This value is NOT List internal name
  • List targetList = clientcontext.Web.Lists.GetByTitle("List Name");
  •  
  • // Get field from list using internal name or display name
  • Field oField = targetList.Fields.GetByInternalNameOrTitle("Column Name");
  •  
  • oField.Indexed = true;
  •  
  • oField.Update();
  • clientcontext.ExecuteQuery();
  • }

Thank you for reading this article. This code was tested in SharePoint 2013

We value your feedback:

Page URL:

Name:

 

Email:

 
 

Feedback:

 

© 2019 Code SharePoint