0

Does any one know how to apply the custom site design to the team site collection URL in SharePoint online through client side object model?

0

You need to use the ApplySiteDesign method of the Tenant class.

In that method, you need to pass the site design's Id. For that you first need fetch the site Design id that you want to apply and then use the ApplySiteDesign method to execute the site design on the site collection.

The code for that would be as below:

var tenantUrl = "https://<tenant>-admin.sharepoint.com";

var tenantContext = new ClientContext(tenantUrl));

var tenant = new Tenant(tenantContext);

var existingDesigns = tenant.GetSiteDesigns();
tenantContext.Load(existingDesigns);
tenantContext.ExecuteQueryRetry();

var existingSiteDesign = existingDesigns.FirstOrDefault(d => d.Title == "Your-site-design-name");

var results = tenant.ApplySiteDesign("<your-site-collection-url>", existingSiteDesign.Id);
tenantContext.Load(results);
tenantContext.ExecuteQueryRetry();

If there are >30 actions, you can se SiteDesignTask as below:

var designTask = tenant.AddSiteDesignTask(tenantContext, "<your-site-collection-url>", existingSiteDesign.Id);
tenantContext.Load(designTask);
tenantContext.ExecuteQueryRetry();

References -

Tenant.ApplySiteDesign

Tenant.GetSiteDesigns

You need to be atleast SharePoint admin to execute this code, being a site collection admin alone is not sufficient if you want to do that via CSOM.

| improve this answer | |
  • Thank you.. Gautam, its worked. – tarun Jul 1 at 5:11
  • Gautam ..It is working if site design have total of 30 verbs/actions (including sub-actions) but not above 30 verbs/action. Do you've an idea how to apply the large site design via CSOM? – tarun Jul 1 at 10:57
  • Updated for >30 actions. – Gautam Sheth Jul 1 at 11:09
  • great.. it's worked.. thank you :) – tarun Jul 2 at 5:35
0

Using CSOM, you can use tenant.applySiteDesign(). You need to pass the web URL and site design ID to this method.

Syntax:

public ClientObjectList<TenantSiteScriptActionResult> ApplySiteDesign(
    string webUrl,
    Guid siteDesignId
)

Official documentation can be found here:

Tenant.ApplySiteDesign method

Also, you can get complete code at: The Ultimate Guide to SharePoint Site Designs and Site Scripts

| improve this answer | |

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.