I think I should be using the ServerRelativeUrl property of SPWeb but am not 
sure how.

I've tried to append the parent site path to the new web's name and now get 
this bizarre error:

"/AboutUs" contains leading or trailing slash, which is invalid

Maybe I should just give up and do this via the template XML but this seemed so 
much more elegant.

Code variation below:

private void CreateSubsites(PublishingWeb currentPublishingSite)
{
if (currentPublishingSite.IsRoot)
{
using (SPSite siteCollection = new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb web = siteCollection.OpenWeb())
{
// Inherit LCID from parent
uint webLCID = Convert.ToUInt32(siteCollection.RootWeb.Locale.LCID);

// Get parent web relative URL
string parentWeb = siteCollection.ServerRelativeUtl;
string webUrl = parentWeb + "AboutUs";

                  // webUrl, Title, Description, LCID, Template, UniquePerms, 
bConvertIfThere
                  using (SPWeb newSite = 
siteCollection.RootWeb.Webs.Add(webUrl, "About Us", "More information about 
this site.", webLCID, _siteTemplateNamePrefix, false, false))
                  {
                        // Perform additional customisations here
}
            }
      }
}
}


From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of 
Paul Noone
Sent: Wednesday, 15 June 2011 12:43 PM
To: ozMOSS
Subject: RE: SPWebCollection Add Method

Thanks Joe. The following works nicely. :)

//Inherit LCID from parent
uint webLCID = Convert.ToUInt32(siteCollection.RootWeb.Locale.LCID);

Now I have one more small problem.

The Web site address "/AboutUs" is already in use.

Which is true, if you're talking about the web application root site 
collection. However, I only want to get the parent site of the web I'm trying 
to create. Looks like I'm heading  too high up the hierarchy.

I'm currently creating the parent at a managed path "teams/newsite". And want 
the subsite to be created at "teams/newsite/AboutUs".

Can I do this without having to use explicit paths?


From: ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] On Behalf Of 
Joseph Clark
Sent: Wednesday, 15 June 2011 12:26 PM
To: ozMOSS
Subject: Re: SPWebCollection Add Method

Oh, of course. Sorry for missing that the LCID is explicitly unsigned in the 
Add method :-).

You should be able to use Convert.ToUInt32 on the LCID property, instead of 
trying to convert to ToString() representation of the Locale.

Cheers,
Joe.
On Wed, Jun 15, 2011 at 12:20 PM, Paul Noone 
<paul.no...@ceosyd.catholic.edu.au<mailto:paul.no...@ceosyd.catholic.edu.au>> 
wrote:
I tried using it directly first time round which is how I wound up stuck with 
messy conversions. :)

Error  1        The best overloaded method match for 
'Microsoft.SharePoint.SPWebCollection.Add(string, string, string, uint, string, 
bool, bool)' has some invalid arguments
Error  2        Argument '4': cannot convert from 'int' to 'uint'

Regards,

Paul

--
Online Developer/SharePoint Administrator,
ICT Infrastructure Team
CEO Sydney

From: ozmoss-boun...@ozmoss.com<mailto:ozmoss-boun...@ozmoss.com> 
[mailto:ozmoss-boun...@ozmoss.com<mailto:ozmoss-boun...@ozmoss.com>] On Behalf 
Of Joseph Clark
Sent: Wednesday, 15 June 2011 12:15 PM
To: ozMOSS
Subject: Re: SPWebCollection Add Method

SPWeb.Locale returns a 
CultureInfo<http://msdn.microsoft.com/EN-US/library/kx54z3k7> object, so you 
should be able to pass the 
LCID<http://msdn.microsoft.com/EN-US/library/system.globalization.cultureinfo.lcid>
 property from this straight into the add method.

eg:

siteCollection.Add("foo", "foo", "bar", siteCollection.RootWeb.Locale.LCID);
On Wed, Jun 15, 2011 at 12:10 PM, Paul Noone 
<paul.no...@ceosyd.catholic.edu.au<mailto:paul.no...@ceosyd.catholic.edu.au>> 
wrote:
OK. Almost there using siteCollection.RootWeb.Locale but now I'm having trouble 
with converting the value.

The following will build without error but just looks plain wrong. Does anyone 
know what type of field I'm dealing with?

//Inherit LCID from parent
string LCID = siteCollection.RootWeb.Locale.ToString();
uint webLCID = Convert.ToUInt32(LCID);

Regards,

Paul

--
Online Developer/SharePoint Administrator,
ICT Infrastructure Team
CEO Sydney

From: ozmoss-boun...@ozmoss.com<mailto:ozmoss-boun...@ozmoss.com> 
[mailto:ozmoss-boun...@ozmoss.com<mailto:ozmoss-boun...@ozmoss.com>] On Behalf 
Of Paul Noone
Sent: Wednesday, 15 June 2011 11:13 AM
To: ozMOSS (ozmoss@ozmoss.com<mailto:ozmoss@ozmoss.com>)
Subject: SPWebCollection Add Method

Hi all,

I'm trying to provision a subsite using this method and am stuck on the nLCID 
parameter.

The API states a 32-bit GUID is required but I can't find one! :)

I want to inherit from the parent Site which uses English-AU but am not sure if 
I'm getting it properly.

Will the following work?

if (currentPublishingSite.IsRoot)
{
using (SPSite siteCollection = new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb web = siteCollection.OpenWeb())
{
                  //Inherit LCID from parent
                  uint webLCID = SPSite.Language;
                  // webUrl, Title, Description, LCID, Template, UniquePerms, 
bConvertIfThere
                  using (SPWeb newSite = 
siteCollection.RootWeb.Webs.Add("AboutUs", "About Us", "More information about 
this site.", webLCID, _siteTemplateNamePrefix, false, false))
                  {
                        // Perform additional customisations here
}
            }
      }
}


Kind regards,

Paul Noone

---------------------------------------------------
Online Developer/SharePoint Administrator
Infrastructure Team, ICT
Catholic Education Office, Sydney
p: (02) 9568 8461
f: (02) 9568 8483
e: paul.no...@ceosyd.catholic.edu.au<mailto:paul.no...@ceosyd.catholic.edu.au>
w: http://www.ceosyd.catholic.edu.au/


_______________________________________________
ozmoss mailing list
ozmoss@ozmoss.com<mailto:ozmoss@ozmoss.com>
http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss


_______________________________________________
ozmoss mailing list
ozmoss@ozmoss.com<mailto:ozmoss@ozmoss.com>
http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss

_______________________________________________
ozmoss mailing list
ozmoss@ozmoss.com
http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss

Reply via email to