PnP core component contains the extension methods which help to achieve the SharePoint task in simple lines of code. So to know more about PnP Core component, have a look at “Introduction to PnP Core Component”.

WebExtensions.ReIndexWeb (PnP Core Component) – This extension method Queues a web for a full crawl during the next incremental crawl.

Supports: SharePoint 2013, SharePoint 2016, SharePoint Online

Assembly: OfficeDevPnP.Core.dll
Namespace: Microsoft.SharePoint.Client

Method:

void ReIndexWeb()

Syntax:
Single Line Code: Web.ReIndexWeb()

Code Snippet:

The following example re-index the current SharePoint website using trimmed version of managed CSOM (PnP Core Component)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using OfficeDevPnP.Core;

namespace PnPSitesCore.Samples
{
 class Program
 {
 static void Main(string[] args)
 {
 string siteUrl = "https://sharepointonline.sharepoint.com";

 AuthenticationManager authManager = new AuthenticationManager();

 //Interactive Login to SharePoint site - Opens a Online signin page to authenticate the user
 var context = authManager.GetWebLoginClientContext(siteUrl);
 //Queues the current site for the full crawl during the next incremental crawl
 context.Web.ReIndexWeb();  

 Console.WriteLine("Press any key to exit.");
 Console.ReadKey();
 } 
 }
}

The above code also available from GitHub.

Re-Index SharePoint web using CSOM (PnP Core Component)
Tagged on:                 

Leave a Reply

Your email address will not be published. Required fields are marked *