tags:

views:

954

answers:

1

In SharePoint 2010, there is a new method CreateWeb in the Sites web service with the purpose to create new SharePoint sub sites. There are, however, a lot of issues with it - well, that is my experience at least. Here is the code that should utilize the web service and its method properly:

Uri site = new Uri("http://sp2010site/"); 
string webServicePath = "_vti_bin/Sites.asmx";
string webServiceUrl = Path.Combine(site.AbsoluteUri, webServicePath);

Sites webService = new Sites();
webService.Credentials = CredentialCache.DefaultNetworkCredentials;
webService.Url = webServiceUrl;

//the following line creates the sub site
string result = webService.CreateWeb("newsite", "New Site", "Site desc", "STS#0", 
    1033, true, 1033, true, 1033, true, true, true, true, true, true, true);

The following code returns Soap exception if something wrong happened (e.g. a sub site with the address "newsite" already exists, or the specified template doesn't exist).

If everything is ok, an InvalidOperation exception is fired with the message "There is an error in XML document (1, 310).", but the site is actually created!

If everything is ok, but I use my own solution instead of the non-default SharePoint template (such as the Team site, i.e. STS#0), I get a Soap exception and the site does not get created.

This has been a terrible experience so far. Please post your experiences with the sub site creation in SP 2010, and even better, post your resolutions to these problems if you have any. Cheers all!

+1  A: 

Steps in SP2010 beta something to create a [sub] site from a [custom] template:

  • Activate your site template
  • Browse to betasoftwaresucks/_layouts/templatepick.aspx
  • Click on the "Custom" tab. You should be able to see your template
  • Open up a tool that can inspect the DOM (e.g. IE Developer Tools or Firebug). The DOM is modified dynamically so just viewing the HTML just won't work unless you're interested in one of the default templates in the default selected tab.
  • Find the value of the option element representing your template. It will look like "{guid}#templatename". Make sure the "Custom" tab is still open or you might not be able to find this.
  • Use that value as the template parameter to CreateWeb.

[I roll my SP SOAP "by hand" so it's trivial to see the full request and response.]

pst
Yeah, you're right, the template string parameter should be provided as a {site_guid}#template_name. However, the InvalidExceptio is still fired every time I call CreateWeb method (and the site does get created). So, the problem remains. Have you been able to create a site using CreateWeb method without any exceptions? This is such a drag... I know it's in beta, but still... :)
Boris
It works fine here. We did have a problem with one site template that failed to load -- but it failed to load under normal mechanisms as well. Hope you find a solution.
pst
InvalidException firing is a confirmed error by Microsoft. Well, I hope they'll fix it in the official release of SharePoint 2010.
Boris