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'm trying to create a site programmatically using a console application, but have been getting an exception whenever I try to add a new SPWeb "The folder that would hold URL'/sites/[sitename]' does not exist on the server."

How do I go about creating this folder? I was under the impression that the SPWebCollection.Add() method would create the necessary paths.

The code I'm using is

SPSite site;
SPWeb web;
SPSecurity.RunWithElevatedPriviliges(delegate()
{
    site = new SPSite([url]);
    web = site.AllWebs.Add("sites/[sitename]", "title", "description", 1033, "STS#1", false, false);
});

Thanks!

share|improve this question

1 Answer 1

up vote 1 down vote accepted
SPSite site;
SPWeb web;
SPSecurity.RunWithElevatedPriviliges(delegate()
{
    site = new SPSite([url]);
    web = site.AllWebs.Add("sitename", "title", "description", 1033, "STS#1", false, false);
});

this should do the trick, just give it the site name and sharepoint will handle the rest :)

share|improve this answer

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.