I have been given a task to create an event that dynamically creates new site collections on our sharepoint webApp. Thing is using Central Admin I can create "http://testsite.com/sites/newSite_1" and it is a top level site.

However SharePoint does not seem to allow new top level sites created from code?

 private void createSite(String newUrl, SPSite Sender, SPUser current)
      SPWebApplication webApp = Sender.WebApplication;
      SPSite mysite = webApp.Sites.Add(newUrl, "Title", "Desc", 1033, null, current.LoginName, current.Name, current.Email))


So. CA -> add "http://testsite.com/newSite1" = top level site

But c# ->add "http://testsite.com/newSite2" = sub site

Where do I go wrong?

1 Answer 1


Normally when you do this, you need to make use of the Managed Paths and create the new site collections under that. In most cases, this is /sites/ but can be changed to whatever suits your needs.

In your example, you would have the root site collection under /newSite1 and then all subsequent site collections would be under /sites/newsite2, /sites/newsite3, and so on.

This approach also makes it very clear where the boundary is for site collections for the purposes of management and administration.

  • I had been using /site/ not /sites/ in my real code. Thank you
    – user13186
    Commented Apr 2, 2013 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.