Here is a very handy PowerShell script that can speed up your web part development in SharePoint. It is a common scenario when you configure an OOB web part, and then you want to export it to XML  in order to integrate it in your custom solution for future deployments. This can occur in various scenarios, and with the arrival of the SharePoint 2013, it will become even more frequent. It works great in SharePoint 2010 also. I find it very helpful especially when working with search verticals, but it can be used in many other situations.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

function EnsureDirectory($exportFolderPath)
 if ( -not (Test-Path $exportFolderPath) ) {New-Item $exportFolderPath -Type Directory | Out-Null}

function ExportAllWebParts($siteUrl,$pageUrl,$exportFolderPath)
 $web = Get-SPWeb $siteUrl
 $wpm = $web.GetLimitedWebPartManager($pageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

EnsureDirectory $exportFolderPath

foreach($wp in $wpm.WebParts)
 $exportPath = $exportFolderPath + "\" + $wp.Title + ".xml"
 $xwTmp = new-object System.Xml.XmlTextWriter($exportPath,$null);
 $xwTmp.Formatting = 1;#Indent
 $wpm.ExportWebPart($wp, $xwTmp);

ExportAllWebParts $args[0] $args[1] $args[2]

# I use this script as a file, ExportWebParts.ps1. The required arguments for this script should be:
#The site absolute URL
#The page site-relative URL
#The folder path for export

#example usage ./ExportWebParts.ps1 Pages/default.aspx C:\temp\Export 

One of the new hot features of SharePoint 2013 is the Work Management Service. This service aggregates tasks from everywhere (SharePoint, Project Server and Exchange) and it also has a “Provider model” that can be used for further integration.

On the UI side, this feature also brings along a very nice web part : My tasks. This web part has different views on all the tasks, and it also provide a rich user interface to view, edit or create new tasks. This post shows more about how My tasks web part can be used by SharePoint Users.

My tasks Web Part

                                         The web part can be found in Content Rollup -> My Tasks

The web part also has three important properties in the Miscellaneous category:

  • Task List Type- gives you the possibility of choosing between different types of views
  • Show view selector – gives the user the possiblity of switching between multiple views
  • Show refresh status – if this option is enabled a small message about the last refresh status is shown at the bottom of the web part
Miscellaneous settings for My tasks web part

Miscellaneous settings for My tasks web part

The web part can be provisioned with xml, and it has a good html structure, so it can be easily customized using css. Here is a sample of how to provision the web part to a page, including the most relevant properties:

 <webPart xmlns="">
 <type name="Microsoft.Office.Server.WorkManagement.UI.TaskListWebPart, Microsoft.Office.Server.WorkManagement.UI, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
 <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
 <property name="HelpUrl" type="string" />
 <property name="Hidden" type="bool">False</property>
 <property name="ChromeType" type="chrometype">Default</property>
 <property name="AllowClose" type="bool">True</property>
 <property name="ShowRefreshStatus" type="bool">True</property>
 <property name="ExportMode" type="exportmode">All</property>
 <property name="AllowMinimize" type="bool">True</property>
 <property name="AllowEdit" type="bool">True</property>
 <property name="Direction" type="direction">NotSet</property>
 <property name="AllowConnect" type="bool">True</property>
 <property name="MissingAssembly" type="string">Cannot import this Web Part.</property>
 <property name="TaskListType" type="Microsoft.Sharepoint.WorkManagement.TaskListType, Microsoft.Office.Server.WorkManagement.UI, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c">Active</property>
 <property name="TimelineViewData" type="string" null="true" />
 <property name="HelpMode" type="helpmode">Modeless</property>
 <property name="Description" type="string"></property>
 <property name="TitleIconImageUrl" type="string" />
 <property name="CatalogIconImageUrl" type="string" />
 <property name="ChromeState" type="chromestate">Normal</property>
 <property name="AllowZoneChange" type="bool">True</property>
 <property name="LastQueryTime" type="datetime" />
 <property name="Height" type="string" />
 <property name="ShowViewSelector" type="bool">False</property>
 <property name="Width" type="string" />
 <property name="Title" type="string">My Tasks</property>
 <property name="AllowHide" type="bool">True</property>
 <property name="TitleUrl" type="string">~sitecollection/AllTasks.aspx</property>

The TaskListType property is an enumeration that can take any of these values:

 public enum TaskListType

This may come in very handy when developing a custom social collaboration portal that includes changes to each user’s personal site.

I have started a new project on CodePlex, a List Item Word Exporter for SharePoint. It offers the possibility to create templates based on Microsoft Word files, and associate them with lists. Using Edit Control Block you can then export any list item to a Word document, based on the predefined template.

Tasks List Example

The template for a Tasks list (left)
List item export based on this template (right)

In the template file, you can define tokens for item values, based on the list field display names, but there are also some built-in tokens for the current user, or the current date time.

Currently, the project only has a release for SharePoint 2013, but a release for SharePoint 2010 will also follow up.

Let me know what you think about it, and what improvements or suggestions you have for the next releases.

In SharePoint 2013 publishing sites, the navigation has been extended, and a new concept emerged: managed metadata navigation. The previous style of publishing navigation is now branded as “Structural Navigation”


In order to work with these settings, new classes were created under namespace Microsoft.SharePoint.Publishing.Navigation.

When a new publishing site is created, as of SharePoint 2013, the default navigation is set to managed metadata navigation. Even if it is a very powerful feature, sometimes you might want to revert back to the classic “Structural navigation”. Here is a PowerShell script that achieves this:

Add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$assembly = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Publishing")

$web= Get-SPWeb $args[0] #web url
$navSettings = New-Object Microsoft.SharePoint.Publishing.Navigation.WebNavigationSettings($web)
$navSettings.CurrentNavigation.Source = 1;
#can also use GlobalNavigation for the top navigation of the site

In another scenario you might want to change the term set the managed metadata navigation is bound to. For this you would have to change the TermSetId of the CurrentNavigation property (for Quick Launch) or of the GlobalNavigation property (for Top Navigation). You can find additional details about working with managed metadata navigation in another post I have published on this topic.

You can find more about working with publishing navigation in SharePoint 2013 here:




Feature stapling is an interesting concept in the SharePoint world, that allows you to associate a feature with any site definition. This feature will be activated automatically when a new site is created  from the associated site definition.

Feature stapling consists of two elements :

  • “Stapler” – the feature that specifies what features to be associated with site definitions

<Elements xmlns="">
<FeatureSiteTemplateAssociation Id="{Guid of the staplee feature}" TemplateName="SPSPERS#2" />
<FeatureSiteTemplateAssociation Id="{Guid of the another staplee feature}" TemplateName="SPSPERS#2" />

This example associates two features with the personal site definition in SharePoint 2013 ( in SharePoint 2010 the TemplateName would be SPSPERS#0 )

  • “Staplee” – the feature associated with a site definition or the feature that applies the customization

This feature can contain anything: a custom master page, list instances, custom pages, custom web parts etc.

The concept itself is fairly easy to use, but an important aspect in feature stapling is the order in which a site is provisioned [see reference about site provisioning order]

  1. global onet.xml
  2. Site-scoped features defined in onet.xml, in the order they are defined in the file.
  3. Site-scoped stapled features, activated asynchronously, on multiple threads
  4. Web-scoped features defined in onet.xml, in the order they are defined in the file.
  5. Web-scoped stapled features, activated asynchronously, on multiple threads
  6. List instances defined in onet.xml
  7. Modules defined in onet.xml

Because of this order of site provisioning, there are some scenarios which raise technical challenges:

  • Suppose your stapled feature depends on another stapled feature. Example – you would like to use publishing infrastructure on the site, and your staplee should be activated after the publishing infrastructure feature was activated.
  • The staplee uses list instances created in step 6.
  • The staplee creates sub-sites for this site definition.
  • The staplee modifies the home page – provisioned by a module in step 7

I have found different methods to deal with this:

1. Use a custom control that executes only once, and hence does all the changes after all the steps in site provisioning have been completed. The technique is explained in Steve Peschka’s blog post here. As a side-note on this, you don’t necessarily have to use a custom master page, you can always register a delegate control in the default master page. This works very well when you want to customize Personal Sites.

2. Wrap your changes in a Feature Event Receiver. You can decide not to execute the code right away (when the feature is activated), but to delay it until the site was provisioned (and all the steps are completed).

public override void FeatureActivated(SPFeatureReceiverProperties properties)
 var web = properties.Feature.Parent as SPWeb;
ThreadPool.QueueUserWorkItem(ApplyYourChanges, web.Url);

private void ApplyYourChanges(object state)
 var webUrl = state as string;
 var uri = new Uri(webUrl);

// additional conditions here -- perhaps check if a feature was activated
 while (!SPSite.Exists(uri))
 using (var site = new SPSite(webUrl))
 using (var web = site.OpenWeb())

//make your changes here


I prefer the second method, as it is cleaner, and doesn’t require a control that makes changes the first time the site is accessed.

Additional References:

Feature Stapling

Site Provisioning Order

Display Templates can also use resource files to favor a multilingual user interface for your SharePoint 2013 site. By looking at the default display templates ( e.g. : Item_Picture3Lines.html, Control_List.html etc. ), I have noticed how language files are used.

The first step would be to deploy a resource file to the master page gallery. This should be a JavaScript file which registers a resource dictionary.

{"resourceKey1": "resourceValue1",
"resourceKey2": "resourceValue2",
"resourceKey3": "resourceValue3"});

The resource file should be deployed to the master page gallery of the site in the Language files folder. Here is an example for a display template used in content search web parts : “_catalogs/masterpage/Display Templates/Language Files/en-US/LocalizedFile_Strings.js” . You have to deploy such a file for each culture you plan to support.

From your display template, you would have to reference the above resource file, using

$includeLanguageScript(this.url,"~sitecollection/_catalogs/masterpage/Display Templates/Language Files/{Locale}/LocalizedFile_Strings.js");

In order to reference a key from your file, you can use :

var localizedResource = $resource("resourceKey1");

That;s it! Now you have localized your display template.

SharePoint 2013 brings several new features in the social and collaboration area. One of these features is the ability to follow content – sites and documents, and receive updates from them in the newsfeed .

When you follow a document, you will get updates in the newsfeed if the item was updated.

FollowingContentFeature NewsFeedFollowDocuments SiteFeedFeature

When you follow a site, this becomes a “channel” for your newsfeeds. You will be able to share posts just within that site.



However, there are two important site features that need to be activated in order to have this functionality available.

  • Following content : this makes the site available to be followed (star icon will appear on the top right part of the screen)
  • Site Feed: this makes the site show up as a “channel” when you are posting something from the newsfeed web part. There is also a web part, called “Site Feeds” which comes with this feature.

FollowingContentFeature SiteFeedFeature

Although some site templates already have these features enabled (e.g. : Team Site), they have to be manually activated for a Blank Site or a Publishing Site.

A simple usage scenario for following sites would be like this:

  • Create a new site collection
  • Activate the required features at site level
  • Create a new page
  • Add the “Site Feeds” web part to the page.


  • Anyone accessing that page, will see the feeds from this site, and will be able to post messages    via this “channel”


  • Newsfeed also appear in the My Site area.


You can find more information about the social capabilities in SharePoint 2013 here.

What do you think about following sites in SharePoint 2013?