Programmatically/automatically RE-index document library sharepoint 2013


 

SharePoint 2013 provides the ability to reindex a document library or a list.

http://office.microsoft.com/en-gb/office365-sharepoint-online-enterprise-help/manually-request-crawling-and-re-indexing-of-a-site-a-library-or-a-list-HA104052395.aspx

You can add an event receiver on itemAdded or itemAdding based on the business logic and implement the code which adds the search version for the document library or list to be re-indexed.

Enjoy, Atul

Event Receiver
/// <summary>
        /// An item is being added.
        /// </summary>
        public override void ItemAdding(SPItemEventProperties properties)
        {
            base.ItemAdding(properties);

            

            SPList list = properties.List;

            this.EventFiringEnabled = false;

            object version = list.RootFolder.Properties["vti_searchversion"];

            int iVersion = Convert.ToInt32(version);

            list.RootFolder.Properties["vti_searchversion"] = iVersion + 1;

            list.Update();

            this.EventFiringEnabled = true;
        }

Advertisements

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: