Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
I had been using /site/ not /sites/ in my real code. Thank you –  user13186 Apr 2 '13 at 17:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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