Some times customers prefer that links to documents opens in the application and in sites we can ensure this by activating this Site Collection Feature:
But how about in Search?
Out of the box Search (aka Microsoft Search) opens in the browser, and as far as I know that can't be changed:
In PnP Modern Search we have a lot more options and by combining Office URI Schemes | Microsoft Learn and Handlebars we can tailor the URL to fit the requirements:
{{#eq FileType 'xlsx'}}
<a href="ms-excel:ofv|u|{{Path}}" data-interception="off" title="{{Filename}}">{{Title}}</a>
{{/eq}}
the real magic is in the Office URI and the Command Name in particular:
ofv = open in view/read only mode
ofe = open in edit mode
etc.
I recommend using FileType over FileExtension as FileType always will be lower case and seems to be more reliable:
You can of course choose to insert the Handlebar in the Title column, but you should be aware that this will ONLY work if the Office pack is installed on the device consuming the search page.
So, if you need this to work in all cases you might have to use two columns where one will open in the app and the other will open in the browser:
You can find the HandleBar in the PnP Modern Search layouts repository, right here:
Comments