Microsoft.SharePoint.Client.ServerException: ‘The managed path sites/SiteName is not a managed path in this tenant.’

In this tutorial, let us see, how to fix errors, Microsoft.SharePoint.Client.ServerException: ‘The managed path sites/SPGuides is not a managed path in this tenant.’

Recently, I was trying to create a site collection in SharePoint Online using CSOM. There I got an error like the below:

Microsoft.SharePoint.Client.ServerException: ‘The managed path sites/SPGuides is not a managed path in this tenant.’

The error looks like below:

The managed path is not a managed path in this tenant
Microsoft.SharePoint.Client.ServerException: ‘The managed path sites/SPGuides is not a managed path in this tenant.’

Microsoft.SharePoint.Client.ServerException: ‘The managed path sites/sitename is not a managed path in this tenant.’

Here I was writing the CSOM SharePoint code like below:

using (ClientContext ctx = new ClientContext("https://tsinfo-admin.sharepoint.com/"))
            {
                ctx.AuthenticationMode = ClientAuthenticationMode.Default;
                SecureString securePassword = new SecureString();
                foreach (char c in "MyPassword")
                    securePassword.AppendChar(c);
                ctx.Credentials = new SharePointOnlineCredentials("[email protected]", securePassword);
                var tenant = new Tenant(ctx);
                var siteCollectionProperties = new SiteCreationProperties();
                siteCollectionProperties.Url = "https://tsinfo.sharepoint.com/sites/SPGuides/NewSPGuideSite";
                siteCollectionProperties.Title = "New SPGuides Site";
                siteCollectionProperties.Owner = "[email protected]";
                siteCollectionProperties.Template = "STS#3";
                SpoOperation spo = tenant.CreateSite(siteCollectionProperties);
                ctx.Load(tenant);
                ctx.ExecuteQuery();
                Console.WriteLine("SharePoint site collection created successfully!");
                Console.Read();
            }

Here, the error was coming because of the below line:

siteCollectionProperties.Url = "https://tsinfo.sharepoint.com/sites/SPGuides/NewSPGuideSite";

When you are trying to creating a site collection, you need to provide the site collection URL directly, not like a subsite. It should be always /sites/<sitecollectionURl>

The correct way of giving the Url is like below:

siteCollectionProperties.Url = "https://tsinfo.sharepoint.com/sites/NewSPGuideSite";

The complete code looks like below:

using (ClientContext ctx = new ClientContext("https://tsinfo-admin.sharepoint.com/"))
            {
                ctx.AuthenticationMode = ClientAuthenticationMode.Default;
                SecureString securePassword = new SecureString();
                foreach (char c in "MyPassword")
                    securePassword.AppendChar(c);
                ctx.Credentials = new SharePointOnlineCredentials("[email protected]", securePassword);
                var tenant = new Tenant(ctx);
                var siteCollectionProperties = new SiteCreationProperties();
                siteCollectionProperties.Url = "https://tsinfo.sharepoint.com/sites/NewSPGuideSite";
                siteCollectionProperties.Title = "New SPGuides Site";
                siteCollectionProperties.Owner = "[email protected]";
                siteCollectionProperties.Template = "STS#3";
                SpoOperation spo = tenant.CreateSite(siteCollectionProperties);
                ctx.Load(tenant);
                ctx.ExecuteQuery();
                Console.WriteLine("SharePoint site collection created successfully!");
                Console.Read();
            }

Now, when you execute the code, the error Microsoft.SharePoint.Client.ServerException: ‘The managed path sites/SiteName is not a managed path in this tenant.’ will not come.

You may like the following SharePoint CSOM tutorials:

In this tutorial, we learned how to fix errors, Microsoft.SharePoint.Client.ServerException: ‘The managed path sites/SPGuides is not a managed path in this tenant.’

>