Problem: You have a custom search display template however when a document library item shows up, which by default links directly to the document itself, you’d rather have a clickable link to the display properties form (dispform) or edit properties form (editform). This is troublesome because as far as I know search results do not provide any properties that link to the display form for the item.

The Ideal Solution

Some properties will link to the list itself  so you could build out a dispform?={ItemID} on the end of that. Things get tricky and not so easy when folders or custom views are used though. I avoided this approach as I did not have luck with code others provided due to lack of folder support and certain scenarios. I did find an approach that seems like it may work very well and has positive feedback here. I would recommend trying this approach first.

The Alternative

I devised a different way around this. It uses a redirect (ugh) but even so it is very straightforward and very few lines of code. I cannot go into detail but I will just explain high level approach.

  • In your displate template, add managed properties SPSiteURL, ListID and ListItemID
  • Create a page that will go into SharePoints _layouts folder with redirect code
  • Have your display template link to the redirect page within the _layouts folder, passing the variables as part of the query string.
  • Add code to the redirect page
    • Grab the site using the typical new Site(SPSiteURL)
    • Call the newly instantiated sites openweb()
    • Using the web grab the list by the ListID guid
    • Using the list grab the item by the ListItemID
    • Redirect to items display form:
      • item.ParentList.ParentWeb.Site.MakeFullUrl(item.ParentList.DefaultDisplayFormUrl);
      • Use SPUtility.Redirect to redirect to the above codes result

The downside is that the link shown to the user, if they decide to hover over it, will be a bit ugly and uninformative. This could be improved by keeping the original link and using javascript to direct elsewhere, perhaps.

This has not been extensively tested but works very well from what has been done with it so far.

 

No Comments

There are no comments related to this article.

Leave a Reply

Your email address will not be published. Required fields are marked *