Forum Discussion
Default view mode/edit mode behavior for Word and Excel Online files
Onno van Ewyk I've replied to this blog post with a solution for this issue. Please see my reply below:
Hi All,
You can achieve setting the default to 'View" mode by using SharePoint Column Formatting.
Simply update your column (in my case I updated Name to keep the experience seamless) with the following json and your documents will now open in Preview instead of Edit:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "a",
"txtContent": "@currentField",
"attributes": {
"target": "_blank",
"href": "=if(indexOf([$ContentTypeId], '0x0120') >= 0, '?id=' + [$FileRef], @currentWeb + '/_layouts/15/Doc.aspx?sourcedoc='+ [$UniqueId] + '&action=View')"
}
}
What this does is checks if the item is a folder and uses existing behavior to open the folder otherwise it will open the document in view mode.
Hope this helps anybody looking for a way to solve this issue!
AndrewFiveP I find your JSON snippet very useful. Folders are handled properly as well, but images and video's are not. I guess it should be possible to add other ContentTypeID so the script uses standard behaviour as well, but I don't know how to do this. Any hints? Thanks.
- AndrewFivePAug 11, 2019Copper Contributor
Martijn Kessels Currently the script simply treats anything other than folders as office documents so it opens them up in office web apps. You can add additional conditions for each additional content type and set their behavior as needed. Unfortunately there isn't a switch function so you'll need to nest if branches =/