Site url exceeds maximum length of 256
-
02-10-2020 - |
Question
I'm trying to create a team site and get the following error message
Site url https://myurl/sites/mylongsitename exceeds maximum length of 256.
The url itself is under the 256 limit, I've also tried appending "Shared Documents" and "Shared%20Documents" and its still under the limit. Does anything else get appended to increase the length.
Is there a way for me to validate this before attempting to create it?
This is the code I am using source
using (ClientContext tenantContext = new ClientContext("https://yoursite-admin.sharepoint.com/"))
{
//Authenticate with a Tenant Administrator
SecureString passWord = new SecureString();
foreach (char c in "password".ToCharArray()) passWord.AppendChar(c);
tenantContext.Credentials = new SharePointOnlineCredentials("admin@yoursite.onmicrosoft.com", passWord);
var tenant = new Tenant(tenantContext);
//Properties of the New SiteCollection
var siteCreationProperties = new SiteCreationProperties();
//New SiteCollection Url
siteCreationProperties.Url = "https://yoursite.sharepoint.com/sites/codesite";
//Title of the Root Site
siteCreationProperties.Title = "Site Created from Code";
//Email of Owner
siteCreationProperties.Owner = "admin@yoursite.onmicrosoft.com";
//Template of the Root Site. Using Team Site for now.
siteCreationProperties.Template = "STS#0";
//Storage Limit in MB
siteCreationProperties.StorageMaximumLevel = 100;
//UserCode Resource Points Allowed
siteCreationProperties.UserCodeMaximumLevel = 50;
//Create the SiteCollection
SpoOperation spo = tenant.CreateSite(siteCreationProperties);
tenantContext.Load(tenant);
//We will need the IsComplete property to check if the provisioning of the Site Collection is complete.
tenantContext.Load(spo, i => i.IsComplete);
tenantContext.ExecuteQuery();
//Check if provisioning of the SiteCollection is complete.
while (!spo.IsComplete)
{
//Wait for 30 seconds and then try again
System.Threading.Thread.Sleep(30000);
spo.RefreshLoad();
tenantContext.ExecuteQuery();
}
Console.WriteLine("SiteCollection Created.");
}
The total length of the url is 148
La solution
I think I have solved this, well from the tests I have done.
It appears if the url is greater than 136 characters you will get this error.
http://tenant/sites/mysitename "This can not be great than 136 characters"
I've tried this on two different tenants
- tenant 1 - https://tenant1/ 32 chars
- tenant 2 - https://tenant2/ 33 chars
- tenant 1 - site name = 97 chars
- tenant 2 - site name = 96 chars
you also have to factor in "sites" - "teams".
This is the only way I can see of validating a site collection. If I'm wrong please let me know.
I've updated this post with a screen shot. The highlighted textbox has a dynamic max length.