1

I am trying to add indexes to the Title, FileRef and UniqueId fields in my library to avoid a list query threshold error. My code is as follows:

private void CreateListIndexes()
    {
        var list = ClientContext.Web.Lists.GetByTitle(AppConstants.Office365SourceDocuments);
        ClientContext.Load(list);
        ClientContext.ExecuteQuery();
        CreateListIndex(list, "Title");
        CreateListIndex(list, "FileRef");
        CreateListIndex(list, "UniqueId");
    }

    private void CreateListIndex(List list, string fieldName)
    {
        var field = list.Fields.GetByInternalNameOrTitle(fieldName);
        field.Indexed = true;
        field.Update();
        ClientContext.ExecuteQuery();
    }

The index on Title is added OK, but the other two fields fail with the following error:

"Microsoft.SharePoint.Client.ServerException: Cannot complete this action."

How can I add an index to these 2 fields?

0

I found that I did not need to add an index to these fields... rather I updated to release 16 of the Microsoft.SharePoint.Client and Microsoft.SharePoint.ClientRuntime dlls (this is the version that supports SharePoint online) and then used the following methods instead of CAML queries:

  • For the FileRef queries: clientContext.Web.GetFolderByServerRelativeUrl or clientContext.Web.GetFileByServerRelativeUrl
  • For the UniqueId queries: clientContext.Web.GetFolderById or clientContext.Web.GetFileById

NB the update from version 15 to version 16 of the dlls was only necessary to use the GetFolderById and GetFileById methods.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.