0

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!

1 Answer 1

1
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 :)

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.