List Aggregator App (SPFx)

Steps to create search center site in SharePoint online using .Net client object model code

Steps to create search center site in SharePoint online using .Net client object model code

In this post we will discuss how to create search center site using .Net client object model code (csom) in SharePoint online (Download PDF for FREE). We can use console application or we can also use the windows form application. Here we will add the windows form application. To work with SharePoint objects we need to add the below details:
– Microsoft.SharePoint.Client
– Microsoft.SharePoint.Client.Runtime
– Microsoft.SharePoint.Client.Taxonomy

Here we need to pass the credentials to connect to the SharePoint online site and then we are calling the CreateSearchCenterSite() method which will create the search center site.



We need to use the WebCreationInformation class to create the site. Here we need to pass parameters like:
Url
Title
Description
WebTemplate (For search the template is “SRCHCEN#0”)
UseSamePermissionsAsParentSite
Language etc.

SharePoint deveopment training course

Below is the full code:

private void button2_Click(object sender, EventArgs e)
{
using (ClientContext context = new ClientContext(“https://onlysharepoint2013.sharepoint.com/sites/Bhawana/”))
{
context.AuthenticationMode = ClientAuthenticationMode.Default;
var secureString = new SecureString();
foreach (char c in “*********”)
{
secureString.AppendChar(c);
}
context.Credentials = new SharePointOnlineCredentials(“*****@onlysharepoint2013.onmicrosoft.com”, secureString);
try
{
CreateSearchCenterSite(context);
}

catch (Exception ex)
{
throw;
}
}
}

void CreateSearchCenterSite(ClientContext context)
{
WebCreationInformation wci = new WebCreationInformation();
wci.Url = “Search”;
wci.Title = “Search”;
wci.Description = “Our Search Center Site”;
wci.UseSamePermissionsAsParentSite = true;
wci.WebTemplate = “SRCHCEN#0”;
wci.Language = 1033;
Web w = context.Site.RootWeb.Webs.Add(wci);
context.ExecuteQuery();
}

Read some sharepoint online tutorials:


Once you run the code, the search center site will be created successfully like below:

Steps to create search center site in SharePoint online using .Net client object model code
Steps to create search center site in SharePoint online using .Net client object model code

Hope this will be helpful.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Bhawana Rathore

Hello Everyone!! I am Bhawana a SharePoint MVP and having about 8+ years of SharePoint experience as well as in .Net technologies . I have worked in all the versions of SharePoint from wss to Office 365. I have good exposure in Customization and Migration using Nintex, Metalogix tools . Now exploring more in SharePoint 2016 :) Hope here I can contribute and share my knowledge to the fullest. As I believe "There is no wealth like knowledge, and no poverty like ignorance"

View all posts by Bhawana Rathore →