Category Archives: Sharepoint

Show a link to document properties in Sharepoint 2010 search result

Using XSL transformation you can edit the apperance of the search results in Sharepoint 2010. One of the most commonly missed features of the default search result is the lack of a hyperlink to a documents properties (eg. DispForm.aspx). Such a link gives the users a chance to preview document properties before eventually opening the document with Word/Excel/Adoboe etc.

Here XSL code to add a hyperlink to the document properties, and also a link to the containing document library. It will also work for Sharepoint 2007. Paste the code into the search results web part using the XSL editor at the appropriate place.

Important. You must register metadata properties ItemID (ows_ID(text)) and Basic4 (Basic:4 (text)) and do a full crawl from Central Admin.

<div class=”srch-Title3″>
<xsl:variable name=”itemid” select=”ItemID”/>
<xsl:choose>
<xsl:when test=”contentclass[. = ‘STS_ListItem_DocumentLibrary’]”>
<xsl:choose>
<xsl:when test=”contains(basic4,’http’)”>
<xsl:variable name=”library” select=”substring-after(substring-after(url,basic4),’/’)” />
<xsl:variable name=”displayUrl” select=”concat(basic4, ‘/’, substring-before($library,’/’),’/Forms/DispForm.aspx?ID=’,itemid)” />
<a href=”{$displayUrl}”>
Show properties
</a>
</xsl:when>
<xsl:otherwise>
<xsl:variable name=”DocLib” select=”substring-after(substring-after(url,sitename),’/’)” />
<xsl:variable name=”MetaDataPath” select=”concat(sitename, ‘/’, substring-before($DocLib,’/’),’Forms/DispForm.aspx?ID=’,itemid)” />
<a href=”{$MetaDataPath}”>
Show properties
</a>
</xsl:otherwise>

</xsl:choose>
<a href=”{sitename}”>
Show library
</a>
<br></br>
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
</div>

More reading: For a full walkthrough of editing search result check out this great article by Jesse Kim. SharePoint 2010: Actionable search results for documents

Edit: Here’s the full XSL: https://danielbergsten.wordpress.com/2011/09/22/show-a-link-to-document-properties-in-sharepoint-2010-search-result-part-2/

Request for the permission of type ‘Microsoft.SharePoint.Security.SharePointPermission failed

Background: Deploying a aspx web application within a Sharepoint site. Such as C:\inetpub\wwwroot\wss\VirtualDirectories\80\CustomWeb.

Security Exception
Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application’s trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the permission of type ‘Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ failed.

Solution: Add this line to your applications web.config file, system.web section:

<trust level=”Full” originUrl=”” />

or

<trust level=”WSS_Medium” originUrl=”” />

Explanation: By default WSS/MOSS is configured with a security policy called WSS_Minimal.  This policy definition doesn’t grant access to the SP object model.