Wednesday, March 27, 2013

Following or favorite pages in SharePoint 2013 using JavaScript

Recently I was tasked with a project requirement that the user should be able to add pages to a favorite list. To me this sounds much like using the new following feature of SharePoint 2013 which allows you to follow documents, sites, people and tags. And the difference between a document and a page in SharePoint is more semantic than technical. Also, we don’t want the user to navigate to the pages library in order to follow the page, but do it with a link/icon on the page itself. That said, the hover panel “Follow” link does not appear by default for Pages libraries either :)

Instead of creating a custom list to hold a users favorites we decided to use the built in social following functionality using JavaScript CSOM.

So, how do you go about following a page? There are at least a couple of ways. One, write your own custom CSOM script, or two, tap into what SharePoint uses when you click “Follow” on a document or a site.
image

Tuesday, March 26, 2013

An easy way to accomplish Home navigation links regardless of the path of your site collection

Most of my team mates deploy project solutions to http://project.server.local/ which means all links used in the solution can be prefixed with “/” and everything is related to the root path and works just fine.

I’m different and use http://server.local/sites/project. And of course all links going to root for me will go to http://server.local instead of http://server.local/sites/project.

The solution, at least for global nav in master pages etc. is to make use of the variable _spPageContextInfo, blogged by numerous people. This object holds several properties about the current page/item you are viewing (see _spPageContextInfo is your new best friend by Sahil Malik for a complete property listing).

The code below is a sample of a hyperlink on an image to the front page of the current site collection.



Saturday, March 9, 2013

Search Query Suggestions for anonymous users in SharePoint 2013–and with security trimming

Query suggestions have improved in SharePoint 2013 and in addition to showing popular queries it can also show people matching your query or popular queries you have executed yourself in the past. But for anonymous users this is not the case.

image

Out of the box, query suggestions will not work for anonymous users as Waldek Mastykarz wrote about back in December 2012. Waldek actually contacted me before writing his post and as I commented on his post, this is due to some hardcoding in the internal code logic in Microsoft.Office.Server.Search.Query.Query

GetQuerySuggestionsWithResults(…)
.
.
if (SearchCommon.IsUserAnonymous)
{
    return new QuerySuggestionResults(new QuerySuggestionQuery[0], new PersonalResultSuggestion[0], new string[0]);
}