Create a sub site based on a custom (Sandboxed) Web Template using Powershell

One quick tip when using Powershell to create a SharePoint sitestructure combined with custom Web Templates (In my case Sandboxed). The correct syntax for creating Webs based on your custom (sandboxed) Web Template is: $site = Get-SPSite http://myserver/sites/mysite  $web = New-SPWeb http://myserver/sites/mysite/subsite   $web.ApplyWebTemplate(“{FeatureGUID}#MyTemplate”)

In this case you can not use the –template parameter on the New-SPWeb method. Hopefully this post will save u the wondering why your PS script is failing.

If you are trying to figure out what the correct name is for the WebTemplate, you can also use this PS command to check which Templates are available in your current Site.

$site = Get-SPSite http://myserver/sites/mysite  $site.GetWebTemplates(lcid)

lcid off course being the language ID.

Inconvenient Recurrence Data from a SharePoint Calendar using Client OM (JS)

The CAML to get SharePoint items from lists has a nice feature when it comes to Calendar data. Using the <DateRangesOverlap/> it is possible to check if a given date is within a range of dates and when passing the ExpandRecurrence property it even takes the Recurrence Data into account. Using Sandboxed Solutions to do so we can easily set this property SPQuery.ExpandRecurrence = true; However when it comes to the JavaScript Client OM we cannot use this property.


The only way to query SharePoint for Recurrence Data using Client OM is by using theGetListItems Method from the List WebService (/_vti_bin/lists.asmx). The XML passed into the WebService can handle QueryOptions and we can use this to specify if ExpandRecurrence should be true. The Soap XML looks like this:

<soapenv:Envelopexmlns: soapenv=’http://schemas.xmlsoap.org/soap/envelope/’>    <soapenv:Body>     <GetListItemsxmlns =’http://schemas.microsoft.com/sharepoint/soap/’>        <listName>[MyListName]</listName>        <query>          <Query>            <Where>              <DateRangesOverlap>                <FieldRefName=’EventDate’ />                <FieldRefName=’EndDate’ />                <FieldRefName=’RecurrenceID’ />                <ValueType=’DateTime’>                  <Today />                </Value>              </DateRangesOverlap>            </Where>          </Query>        </query>        <queryOptions>          <QueryOptions>            <ExpandRecurrence>TRUE</ExpandRecurrence>            <CalendarDate>              <Today />            </CalendarDate>            <ViewAttributesScope=’RecursiveAll’ />          </QueryOptions>        </queryOptions>        <viewFields>          <ViewFields>            <FieldRefName=’EventDate’ />            <FieldRefName=’EndDate’ />            <FieldRefName=’fAllDayEvent’ />            <FieldRefName=’fRecurrence’ />            <FieldRefName=’Title’ />          </ViewFields>        </viewFields>        <RowLimit>10</RowLimit>      </GetListItems>    </soapenv:Body>  </soapenv:Envelope>

This example checks if there are events overlapping with <Today />. I found that it’s best to check with tags like <Today/>. <Week/>, <Month/> and <Year/> instead of using UTC Dates. Notice the <queryOptions/> wrapper passing the Options. Building regular CAML XML using the inner <QueryOptions/> tag didn’t work unfortunately. Both <ExpandRecurrence/> as <CalendarDate/> are mandatory in order for this query to work.

Tip: When using Client OM to process SharePoint data requests it’s best practice to specify as much properties as possible. Specifying <ViewFields/> will only return these fields instead of all possible fields that come with an Item. If you know the maximum amount of results specifying <RowLimit/> also helps to improve the performance on your Query.