1

I'm trying programmatically to create a site from a web part, sandbox solution for SharePoint Online 2010. My web part has a text box which displays error messages and a button Create, in which on click event creates a site.

If the parameters of my method are

web.Webs.Add("TestAccount", "TestAccount", String.Empty, web.Language, SPWebTemplate.WebTemplateSTS, false, **true**);

Whether the template is my custom template or SharePoint site template (Team Site), I get an error:

"Cannot convert a folder if a web template is specified."

If the parameters of my method are

web.Webs.Add("TestAccount", "TestAccount", String.Empty, web.Language, SPWebTemplate.WebTemplateSTS, false, **false**);

I get an error:

"The web site address is already in use."

Even though there is no site in the workspaces under TestAccount name and it has not been created.

using (SPSite site = SPContext.Current.Site)
        {
            using (SPWeb web = SPContext.Current.Web)
            {
                webTemplates = site.RootWeb.GetAvailableWebTemplates(1033);
                foreach (SPWebTemplate webTemplate in webTemplates)
                {
                    if (webTemplate.Title == "Engagement Site")
                    {
                        myTemplate = webTemplate;
                    }
                }
                 bool allowUnsafeUpdates = web.AllowUnsafeUpdates;
                    web.AllowUnsafeUpdates = true;
                    accountSite = web.Webs.Add("TestAccount", "TestAccount", String.Empty, web.Language, SPWebTemplate.WebTemplateSTS, false, true);

                    accountSite.Update();
                    web.AllowUnsafeUpdates = allowUnsafeUpdates;
            }
        }

1 Answer 1

-1

I think the fact that you are creating sites out of a sandbox solution is the reason why you can't create sites. Try deploying as a farm solution

2
  • You can only create sandbox solutions for SharePoint Online and the OP states that it is the platform they use. Also, site creation is allowed for sandboxed solutions. Commented Jul 3, 2013 at 12:34
  • The answer was still leading in the same direction no need for a downvote Commented Aug 15, 2013 at 12:45

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.