Wednesday, 25 January 2012

SharePoint 2010 - SPCalendarView Issues

When using the SPCalendarView within a web part I encountered an issue where the calendar was incorrectly displaying the calendar events when moving between the current, previous and next month.  The control correctly displayed the current month ,however, the previous and next month were not displaying as expected.

I had tested the SPCalendarView control within a RTM version of SharePoint and it worked as expected.  However,  when I updated my development environment with the June 2011 cumulative updated the behaviour described above was encountered. 

I noticed that if I disabled the V4Rendering on the control it functioned as expected, but that resulted in a lost of the Ajax functionality.

I subsequently updated my environment with the October 2011 cumulative updated but the issue was still present.

Recently I applied the December 2011 cumulative update and I am glad to report that this issue has now been fixed.

“Applying a cumulative update to SharePoint is not a process to take lightly.  It is recommended that you taking a backup of your SharePoint farm before undertaking any update as you cannot uninstall them. Click here for more information about the contents of the relevant cumulative updates.”

SharePoint 2010 - Debug Timer Job

In order to debug a timer job or a code section within a workflow that occurs after a delay you need to attach the visual studio debugger to the OWSTIMER.exe process.

This can be done using the following steps:


Click On Debug then Attach To Process



Within the Attach to Process window ensure the Show process from all users checkbox is selected.  Find The OWSTIMER.exe process within the available processes then click Attach.

Attach to Process

After these steps you should now be able to debug your timer job code.

SharePoint 2010 - Debug Workflow After A Delay

The debugging features within Visual Studio are extremely useful when trying to track down the cause of a failure within your workflow code.  

To debug your workflow you usually attach the debugger to the relevant w3wp.exe process.  However, if your workflow contains a “Delay Activity” then SharePoint no longer uses the w3wp.exe process to execute the code after the delay but the OWSTIMER.exe (Time Job) process.

Workflow Diagram

Using the workflow diagram above as an example:


This code block executes within the w3wp.exe process.


This code executes within the OWSTIMER.exe process.

“Click here for details on how to attach the visual studio’s debugger to the OWSTIMER.exe process.”

Thursday, 5 January 2012

SharePoint 2010 - Get Web Template Name

Site templates provides a simple and quick way of provisioning new sites with common lists and library's.

However, in order to programmatically create a site from a template it is necessary to know the internal name used to reference the web template. 

The format of the internal name for a custom web template is a Guid followed by a hash followed by the template name.  You can find the name for the template using either PowerShell or C#.


The following PowerShell can be used to output the full template name for a given template.

$site = Get-SPSite -Identity http://sharepoint
$site.GetWebTemplates(1033) |  Where-Object {$ -like "*[TemplateName]*"} | Select Name

The following PowerShell can be used to output all the full templates within the site collection.

Get-SPWebTemplate | SELECT name



The following C# can be used to find the desired web template given the templates name.

private string getWebTemplate(string SiteUrl, string WebTemplateName)
    string TemplateName = string.Empty;
    using (var site = new SPSite(SiteUrl))
        using (var web = site.OpenWeb())
            SPWebTemplateCollection templates = web.Site.GetWebTemplates(1033);
            foreach (SPWebTemplate template in templates)
                string[] templateInfo = template.Name.Split('#');
                string CustomWebTemplateName = templateInfo[1];
                if (CustomWebTemplateName.ToLower().Equals(WebTemplateName.ToLower()))
                    TemplateName = template.Name;
    return TemplateName;

Once you have the full template name for the template you can then using it to programmatically create a site. Click here to see how to programmatically create a site using a web template.

SharePoint 2010 - Save Site Template

A site template provides a simple and quick way of provisioning new sites with common lists and library's.

The following steps detail how to save a site as a site template.

Step 1

Within the site you wish to save as a template click Site Actions then Site Settings.

Site Settings

Step 2

Within the Site Actions section click on Save site as a template

Site Actions


Enter the filename for the template and then name of the template.  If you wish to include any existing list items within the lists then select the include content checkbox.  Then click OK.

Save as template


Once the template has finished saving a conformation message will be displayed with a link to the solution gallery where the template has been saved.

Operation Successful


Within the solution gallery the new template should now be visible.  Now when new sites are creation within SharePoint the template will one of the options to choose from.

Solution Gallary

SharePoint 2010 - Create Site From Template

Creating a SharePoint site from a site template provides a simple and quick way of provisioning new sites with common lists and library's.

Click here to see how to save a site as a site template.

Once a site has been saved as a site template you can use it as a base to create new sites.  This can either be done through the standard SharePoint interface or through code.

C# – Create Site From Template

private void CreateSiteFromTemplate(string strWebUrl,string strTitle,string strDescription)
            using (var curSite = new SPSite("http://SharePoint"))
                using (var curWeb = curSite.OpenWeb())
                    uint nLCID = 1033;

                    SPWebTemplate WebTemplate = curWeb.Site.GetWebTemplates(1033)["Guid#TemplateName"];

                    curWeb.Webs.Add(strWebUrl, strTitle, strDescription, nLCID, WebTemplate, false, false);                     


Key Line

The code block below is used to specify which template is to be used to create the new site.  When using a custom template the format of the template name is a Guid followed by a hash then the name of the template name.

Click here to see how to find out the internal name for a custom site template.

SPWebTemplate WebTemplate = curWeb.Site.GetWebTemplates(1033)["Guid#TemplateName"];