SharePoint 2013 Search : Crawl Property bags

Hello Everybody ,

I had just posted an article in my new blog explaining how to use search to index SPWeb.AllProperties.

Here is the link : SharePoint 2013 Search : Crawl Property bags


SandBox solution : provision publishing page with custom web parts


In my last article i talked about provisioning publishing pages with a module on sandboxed solutions.

Today i will talk about adding custom WebParts to a provisioned publishing page.

On farm solutions we need only type of the WebPart and the import error message. But on sandbox we need to specify the id of the solution that deployed the WebPart :







You can find the solution ID on the manifest file of the package.


Sandbox Solution : Provision publishing page

Last year while working with sandboxed solution for SharePoint 2010, i faced a problem while creating a module to provision publishing pages with WebParts.

Problem :

I used this code :






I added this module on a feature, but when i activate the feature i get :

  1. The page is draft
  2. The WebPart is not added.

Solution :

This approach assume that the file “page.aspx” will be copied on the 14 folder on the feature folder. However SandBoxed solutions do not have access to root folder.

The solution is to use a file which is already on the SharePoint root folder :





What i changed is the “SetupPath” , this property is used to specify a physical path to a folder that contains a file to include on the module.

I will use the file “SiteTemplates\SPS\default.aspx” so i set SetupPath to “SiteTemplates\SPS” and the Path of the file to “default.aspx”.

And now everything is working fine 🙂


User Profile property not appearing in search

Hello Everybody.

Today i am going to talk about a problem i got twice(on sharepoint 2010 and 2013).

It is about some user profile properties that are not crawled.

Solution :

Well you have to check 4 important things :

  • At least one user profile has informations on this field/property.
  • You selected “Everyone” on user policy : when you edit each user profile on central admin.
  • The property is Searchable : user profile service application -> Manager user properties
  • The crawled property is mapped to “ContentsHidden” managed propery(in addition of your managed property)

Example :

If you want to crawl the Manager property you have to :

  • Edit some user profiles to fill their Manager, and make sure you chose “Everyone”


  • Make sure that the user profile property “manager” is searchable



  • Map the crawled property People:Manager to the managed property  “ContentsHidden” (if the crawled property is not yet created perform a full crawl)


I hope that my article will help you.




Search Results Web Part Exact pagination

Introduction :

Hello everybody. I will talk again about the Search Results Web Part. But this time it will be about how results are displaying, and especially the pagination.

I think you all know that the pagination on standard control templates is approximative, and number of results is not exact.





As you see , first it shows only 2 pages and when we paginate the number of pages changes. Same thing for the number of results ,we see “About 8 results”.

Today we will “correct” this problem, and make an exact pagination, with the exact number of results.

Here we are going to change the way how Search Results shows the set of results, so we have to change the Control Template.

Solution :

Let’s start by downloading the Control Template “Default Results” and edit it.

The default Control Template(and all standard sharepoint control templates) uses the array “pagingInfo” :

                    var pagingInfo = ctx.ClientControl.get_pagingInfo();

That array changes when we paginate and does not give exact informations. So we have to calculate with ourselves the pagination informations.

What we need to do it? Well we need the number of element per page, and the number of found items:

var resultsPerPage = ctx.DataProvider.get_resultsPerPage();
var totalRows = ctx.DataProvider.get_totalRows();

Now we can get the exact number of pages and the exact results number template:

var nbPages = Math.round(totalRows / resultsPerPage);
var exactCount = Srch.Res.rs_ResultCount;

One last thing is missing : the current page number. We can not use a global variable, because the control template is re-executed every-time we paginate. We will use the pagingInfo array just to get the number of current page.

We have just to iterate over the pagingInfo array and search the item that has StartItem equal to -1:

var currentPage = 1;
for( var i=0;i < pagingInfo.length ; i++){
         if(pagingInfo[i].startItem == -1)
           currentPage = pagingInfo[i].pageNumber;

To have the same design as the standard pagination we will generate exactly the same HTML.

We start by generating the “previous” link :

var prevPage;
var iconClass = “ms-srch-pagingPrev”;
     prevPage = currentPage – 1;
    var indexElem = ((prevPage-1) * resultsPerPage) + 1;
     <li id=”PagingImageLink”>
         <a id=”PageLinkPrev” href=”#” class=”ms-commandLink ms-promlink-button ms-promlink-button-enabled ms-verticalAlignMiddle”
              title=”_#= $htmlEncode(prevPage) =#_” onclick=”$getClientControl(this).page(_#= $htmlEncode(indexElem) =#_);return Srch.U.cancelEvent(event);”>
                  <span class=”ms-promlink-button-image”>
                       <img src=”_#= $urlHtmlEncode(imagesUrl) =#_” class=”_#= $htmlEncode(iconClass) =#_” alt=”_#= $htmlEncode(prevPage) =#_” />

Now we iterate over number of pages and generate links :

for(var j=1; j <= nbPages; j++)
  var indexElem = ((j-1) * resultsPerPage) + 1;
  var idPagingLink=”PagingLink”;
  if(j == currentPage){
   <li id=”_#= $htmlEncode(idPagingLink) =#_”>
        <a id=”A2″ href=”#” title=”_#= $htmlEncode(j) =#_”
onclick=”$getClientControl(this).page(_#= $htmlEncode(indexElem) =#_);return Srch.U.cancelEvent(event);”>

                       _#= $htmlEncode(j) =#_

Now we generate the “next” link (so same thing as the previous link).

Finally we have to update the exact results number label :

<div id=”ResultCount” class=”ms-srch-resultscount”>
     _#= String.format($htmlEncode(exactCount ), $htmlEncode(totalRows.localeFormat(“N0”))) =#_

And now we can see the complete pagination with the exact number of elements :

Exact Pagination




I hope that my article will help you.

See you soon.




Search Results Web Part Sorting not working

Introduction :

Hello everybody. Today i got another problem with the Search Results Web Part.

I wanted to sort results. I went on “Sorting” tab and choose to sort by one of my own properties.

Sorting Search Results Web Part






When i test the query with the simulator it is working fine. But when i apply modifications and went back to the page i see results sorted on creation date!

Problem :

After spending hours searching on Internet, i found many blogs talking about the same issue. It seems that it is a bug with the Search Results Web Part.

The only solution that they suggest is to create a new result source and make sorting on it.

I did not like that solution so i decided to inspect again the xml of the Web Part.

Solution :

I found the property “AvailableSortsJson”Available Sort JSON


As its name indicates, this property specifies the available sorts. I put my property on first rank :

[{“name”:”Display Name of your sort”,”sorts”:[{“p”:”Name of property”,”d”:1 for descending/0 for ascending}]}]

And now everything is working fine.


Search Results Web Part Missing results

Introduction :

Hello everybody. Today i got a problem with the Search Results Web Part.

I added the Web Part manually, and configured it. and when i finished i exported it and add it to a module.

But when i activate my module , i do not see all expected results.

I spent 2 hours on trying to understand. First i thought it is caused by my custom template.

Solution :

I started reading all the xml of the Web Part, until finding “TrimDuplicates” on the DataProviderJson.

I said maybe SharePoint considers some of my results as duplicated. I set that property to false and i could see all of expected results.