Tuesday, April 29, 2014

How-to display file format icons for Document Links

imageYou might have a document library which has the ability to add Link to a Document.

This is useful if you link in items from another document or information repository than SharePoint. Often the links will point to Office format files or PDF’s which is all good, and they display just fine in the document library with icons.





image

You see the PDF icon with a small arrow overlayed. These are actually two images, one for the icon and one for the arrow.

Once you go to the search page the story is different. icons does not show as the links themselves are stored as .aspx files in the library.

Welcome to the IT(comm)Unity


A new kid is on the block! I'm very excited to be part of the launch of IT Unity, an incredible new site that empowers individuals and organizations to solve business problems with technology. IT Unity is a community of trusted experts, users, business decision makers, IT professionals, developers, and industry solution providers - everyone who works with Microsoft SharePoint and Office 365 and is interested in sharing their knowledge can find a home at IT Unity.

At ITUnity.com, you'll find a site where you can:
  • CONNECT with world-renowned subject matter experts and peers in community-driven forums. Take advantage of experts' regular office hours and ask the questions. Gain invaluable insight through lively discussion of issues that community members are facing.
  • SHARE how you've solved a problem, created a service or product, or developed expertise. IT Unity's global audience and network of industry relationships will enhance your visibility and the impact you can make on the broader community.
  • DISCOVER how SharePoint, Office 365, and other technologies can drive innovation and business value. Find best practices, guidance, answers and lessons learned from experts and organizations that have tackled the challenges you face.
  • DEVELOP your knowledge, your skills, your reputation, and your professional network.
At the moment the main driving forces behind the IT Unity content are Dan Holme, Andrew Connell and Scot Hillier, but may other experts have already contributed content to IT Unity. You will continue to see my stuff on this blog, but I’ll also post over at IT Unity, the thought is to create more tutorials than direct solution solving posts.

There are big plans for IT Unity and we would love for you to become part of this CommUNITY. Tweet it up over at @itunity01!

Thursday, April 24, 2014

The 100% way of getting your custom properties to show in your Display Templates

I’ve been meaning to blog this for some time, so here goes.

The issue is that you create a custom display template, and in that template you add a custom managed property which you want displayed like I have here with LinkOfficeChild.

<mso:HtmlDesignAssociated msdt:dt="string">1</mso:HtmlDesignAssociated>
<mso:ManagedPropertyMapping msdt:dt="string">'Title':'Title','LinkOfficeChild':'LinkOfficeChild'</mso:ManagedPropertyMapping>
<mso:HtmlDesignConversionSucceeded msdt:dt="string">True</mso:HtmlDesignConversionSucceeded>

The next step you do is create a new Result Type, set your trigger conditions and choose to use your custom display template.

image


Solution to displaying attachments for a list item in a search result

Matthew McDermott has done it again people! He has given me yet another hard problem to solve. This time it’s about getting the number of attachments of a list item in your search results. And as an added bonus, I’m throwing in the attachment links as well (which actually is a side effect).

image

As it turns out there is no managed property named anything related to attachment or count which will return the number of attachments or the attachment links. That is, if you check the TechNet list or view the search schema via the UI.
Topics covered in this post:
  • Debugging using Search Query Tool v2 – with experimental features turn on
  • The undocumented managed property LinkOfficeChild
  • Custom display templates

Wednesday, April 23, 2014

Sorting a view on the Document ID column in SharePoint 2013/Online

I got a request yesterday where a user wanted to be able to sort a list view via the column heading of the Document ID column. Out of the box this is not doable as the column shown is a URL redirect column which is not sortable, and not the Document ID column iteself.

Read more: You can read more about configuring and activating Document IDs at office.microsoft.com

image

I know there are posts out there which shows how to do this in SharePoint 2010 using SPD, but those days are gone. So what’s the approach then? JS Link!

Tuesday, April 22, 2014

Adding a content type to a list using CSOM in JavaScript throws “Collection has not been initialized” error

My colleague Janaka at Puzzlepart is writing a CSOM PowerShell script to add a content type to a custom list. Doing this he stumbled upon an interesting/weird error.
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)
$clientContext.Credentials = $credentials
$site = $clientContext.Site;
$web = $site.RootWeb;           
$ct = $web.ContentTypes.GetById("0x0100FE72F7843250314FB0ED7A98DCE072C1")
$clientContext.Load($site)
$clientContext.Load($web)
$clientContext.Load($ct)
$list = $web.Lists.GetByTitle("Test One")
$cts = $list.ContentTypes
$clientContext.Load($cts)
$cts.AddExistingContentType($ct)
$clientContext.ExecuteQuery()

Once you execute the above code in a function, line 12 will throw the following error and stop your script.

format-default : The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
+ CategoryInfo          : NotSpecified: (:) [format-default], CollectionNotInitializedException
+ FullyQualifiedErrorId : Microsoft.SharePoint.Client.CollectionNotInitializedException,Microsoft.PowerShell.Comma   nds.FormatDefaultCommand

Wednesday, April 16, 2014

Explaining SQL alias to a dummy

“If I wear a Donald Duck mask you think you are talking to Donald Duck. Then I give the mask to someone else, and you still think you are talking to Donald Duck”

image

“As long as you’re talking to Donald Duck, you get Donald Duck, which is all that matters”

Tuesday, April 15, 2014

I'm Speaking at the European SharePoint Conference 2014

espc-badgeThe European SharePoint Conference is less than three weeks away and I’m super excited to be part of such an exceptional line up. The conference will take place in Barcelona, Spain from the 5-8th May 2014 and is Europe’s largest SharePoint event bringing you great sessions and the latest innovations from Vegas. This will be my first trip ever to Barcelona, so it better be good!

Browse through the superb conference program including 110 sessions, keynotes, and tutorials, including topics covering the latest news from SPC14 including what's new with SharePoint 2013 SP1 - Office Graph/Oslo - new Office 365 REST APIs - Access Apps - Cloud Business Apps.

I will be conducting a session on “Rock Your Office 365 (SharePoint Online) Search with 13 Easy Tune-Ups”, so much more end-user oriented compared to my SPC14 talk on relevance tuning.

 

Page hanging on load in SharePoint–SOLVED!

I recently had an issue which manifested itself specifically in the date picker in SharePoint 2010 where it took around 3 seconds for the picker to show after it was clicked. The error occurred regardless of browser (Chrome, IE10, IE11) and regardless of operating system (Windows7/8, OSX) – but somehow it did not show on my Surface 2.

I tried to investigate the issue with Fiddler and network monitor in the browsers dev tools, but didn’t see anything which made me trigger. I then posted the questions among my peers and Ed Musters reminded me again of using Fiddler, which was a week ago. Today I had the courage to revisit the issue and start investigating.

What did I find… a request from my page hanging on load. The page tried to load a resource from https://_layouts/Folder/somestyles.css.

Hmmm… no host name in that request. I next examined the html of the page and found the following line:
<link rel="stylesheet" type="text/css" href="//_layouts/Folder/somestyles.css"/>

Notice the double slashes in the start of the link.

Ladies and gentlemen, THOSE SLASHES ARE THE CULPRIT!!

Note: // is ok in scenarios where it's followed by a resolvable DNS hostname, where // is translated by the browser to either http:// or https:// depending on which protocol your page is served from.

The resource had been included via setting the AlternateCssUrl property, and the failing code looked as follows:

cssUrl = string.Format("{0}/{1}", site.RootWeb.ServerRelativeUrl, cssUrl.TrimStart(new[] { '/' }));

What happens is that the server relative URL of the root web is “/” and the string format part adds another slash. The code should have checked if the root web was on a path named site collection or not (length > 1), or trim/replace double slashes in the line after.

Changing  the URL to start with just one slash did the trick and the date picker now loads before you can say CODE-REVIEW.

Monday, April 14, 2014

Workaround to show Contact items in People Search

The good thing about community is that it spawns off a lot of ideas for blog posts. The idea for this post I got after my search buddy Matthew McDermott wondered if there is a way to blend results from the Local SharePoint search index with the Local People search index. And his question was spawned from this SO question, asked by Alvaro Monton.

Technically both SharePoint content and People search are in the same search engine, but they have been separated and use different search schemas and ranking.

[Update - 2014-04-15]
In SharePoint 2013 on-premises it's still possible (noticed by Alvaro), but you have to do the other way around. Choose "SharePoint Search Results" as the type, and include people results explicitly. Something like:
{?(({searchTerms}) ContentClass=urn:content-class:SPSPeople)} {?OR (({searchTerms}) spcontenttype:contact)}

[Update – 2014-04-14]
It is indeed possible, but only in SharePoint Online it seems. I tried in SPO on the tenant level and did the following. Create a new result source, pick “People Search Results” as the type, and change the query to the following:
{?({searchTerms})} {?OR (({searchTerms}) spcontenttype:contact)}
You still need to do work on the control and possibly display template to get it to show correct.
If you are on-premises, you might have to resort to the blend workaround.


What doesn’t work is to create a new Result Source which searches both, as you have to pick “SharePoint Search Results” or “People Search Results” as your index source.

What does work, is creating a query rule for people search which add a result block with for example Contact items.

Disclaimer: The following sample is not production ready, but show the concept of blending results.
Topics covered:
  • Create a new result type
  • Create a query rule with routing
  • Create a custom control template to merge results

Friday, April 4, 2014

S15E02: KQL–On Kryptonite

Want the book? Go get it!

This is the second episode my series “SharePoint Search Queries Explained - The Series”. See the intro post for links to all episodes.

In episode one I covered the basic query operators of KQL. In this episode I will cover the advanced ones, as well as show samples of how it can all be put together in useful scenarios together with some nice to know managed properties.

Content Search Web Part “Hello World” using Query Rules

Helge Solheim did a post on how to do “Hello World” using the CSWP, where he retrieves a document with the title of “Hello World”.

Figured I’d do the same, using a Query Rule instead Smile

I first tried to create a rule which triggers on a search term, and then configuring the CBWS to execute that query. But turns out if you do this, the rule will not fire for some reason.

Hence it got a bit more complicated.