Add Search Verticals by code
Anatoly Mironov
Adding own search verticals is a common task in the Search Configuration in SharePoint. Here I want to share a code sample for achieving this programmatically. I hope, this model can be added to SPMeta2. First of all, Search Verticals are dedicated Search Results Pages and links to them. How to add them manually is described on technet:
There is no API in CSOM for that. Luckily, Mikael Svenson found how to get the Search Navigation and contributed to PnP by writing an Extension: web.LoadSearchNavigation. Here is my sample code for adding new Search Verticals programmatically:
NavigationNode searchNav = context.Web.Navigation.GetNodeById(1040);
NavigationNodeCollection nodeCollection = searchNav.Children;
NavigationNodeCreationInformation everything = new NavigationNodeCreationInformation {
Title = "Everyting", Url = "/search/Pages/results.aspx",
};
NavigationNodeCreationInformation myresults = new NavigationNodeCreationInformation {
Title = "My Results", Url = "/search/Pages/myresults.aspx",
};
nodeCollection.Add(everything);
nodeCollection.Add(myresults);
context.ExecuteQuery();comments from wordpress
Johan bergqvist — 2015-10-04
Neat Anatoly. :)
