HiddenNetwork.com Banner
Showing posts with label Search Customization. Show all posts
Showing posts with label Search Customization. Show all posts

Wednesday, August 01, 2007

Modifying Search to Add a Send Link By Email link

My customer wanted a "send link by email" next to each search result item. "Easy", I thought and went ahead to edit the xslt for the search results. But I found out a problem with links that had spaces in them - the link in outlook would appear broken. To solve this, I had to write some simple javascript, and the process is described below.

Problem:
If you want a mailto link (href="mailto") that has in the body a link to a file, you may get a link like this:
href="mailto:body=http://server/site/library/this is my file.doc"
This is a problem, because the file name contains spaces. The email will open with a broken link in it's body:

Solution:
Luckily, SharePoint has a javascript functions that solves that for us. They are "escapeProperly" and "navigateMailToLink". What I did is create a function of my own in the page:

function SendEmailWithLink(link)
{
      var link = "mailto:?body=" + escapeProperly(link);
      navigateMailToLink(link);
      return false;
}

And my link is:
href="#nowhere" onclick="javascript:SendEmailWithLink('');"

This article would'nt be complete if I didn't explain why I did this - this if for the search results xslt - the idea was to add a "send link by email" button next to each search result. The solution - change the xslt to include the script above, and a button like this:

<a title="E-mail a Link" href="#nowhere">
      <xsl:attribute name="onclick">
         javascript:SendEmailWithLink('<xsl:value-of select="$url"></xsl:value-of>');
       </xsl:attribute>
       <img border="0" src="/_layouts/images/ICMSG.GIF"/> 
</a>

We also added other actions (I will try to get them published) and came up with the following for each result item:

Wednesday, April 25, 2007

Error: "An item with the same key has already been added." When modifying the search results web part's XSLT

When you modify the xslt in the people core results web part, you may get the following error (I get it everytime) when you click "OK" in the web part settings:

System.ArgumentException: An item with the same key has already been added. 
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) 
at Microsoft.Office.Server.Search.WebControls.PeopleCoreResultsWebPart.SetSortedRefinementDataOnHiddenObject() 
at Microsoft.Office.Server.Search.WebControls.PeopleCoreResultsWebPart.GetXPathNavigator(String viewPath)
This is very annoying and I do not know how to solve it. But if you get it, don't worry - your change has been made, and you just need to check-in\publish the page to see the effect. The problem ofcourse is that you may not want to check-in the page without seeing the result first, and there is no way around this...