Aug 09 2018 09:09 AM
Aug 09 2018 09:09 AM
I can't find the documentation for this, but I think it's a relatively new feature. I want my Word/Excel/PowerPoint online files to open in view mode instead of edit mode. When you open an Office Online file, the URL is like this [site collection]/_layouts/15/Doc.aspx?sourcedoc=[source location]&action=default&mobileredirect=true&DefaultItemOpen=1. The three paramtersare action, mobileredirect, and DefaultItemOpen.
Does anyone know how to change the action parameter so that its value is "view" instead of "default"? Is this set at the tenant level, or site collection and/or library level?
Oct 16 2018 04:43 PM
I would like to be able to change this default view as well.
On the default site, any document library opens the document in Editing View, but, I noticed that on a new site created with Microsoft Teams, the default view when Word Online opens is Reading View.
Nov 07 2018 12:36 PM
I want to do this as well. I have trolled through all the settings that I could think of with no success. Were you able to find out how to do it?
Nov 07 2018 01:27 PM
Hi Bynum Hoekstra
I had a bit of a look around and found this blog post in which some of the responses give hope for a solution.
Jul 08 2019 06:22 PM - edited Jul 23 2019 03:53 PM
@Onno van Ewyk I've replied to this blog post with a solution for this issue. Please see my reply below:
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:
"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!
Jul 23 2019 12:47 PM
Thank you for this snippet! It has almost resolved the issue for me, it does open the documents in read only mode, but it also breaks the folders so that when a user clicks on them it opens a new window stating an error has occurred. It seems like the part that is supposed to ignore folders is not working correctly, but I am not familiar with JSON so I cannot change the behavior
Is there something I need to change in the JSON snippet to make it ignore folders?
Jul 23 2019 03:55 PM
Whoops! Looks like you're right and this was too purpose built... I've updated the JSON in my post to reflect a wildcard search for the folder content type that works better in any situation.
Let me know if that fixes the issue for you!
Jul 23 2019 04:27 PM - edited Jul 23 2019 04:28 PM
Hi Andrew! Thank you for replying! I just tested the updated JSON and it is still behaving the same way, the files open in view mode no problem, but the folders still open into an error page which I have attached. It states that the Object reference is not set to an instance of an object. Thank you again for replying and getting a solution out there for this! Please let me know if I can give any other information that would be helpful.
Jul 24 2019 06:39 PM
@meyvazi2345 Oh dear, Im not 100% sure what might be occurring here... Are you using this in SharePoint online? I did find that this solution will struggle with folders that have special characters that will cause the URL to break...
Aug 09 2019 01:27 AM
@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.
Aug 10 2019 08:51 PM
@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 =/
Jan 19 2020 07:27 PM
@AndrewFiveP we used your code snipped and it was working a treat. However, SharePoint must have changed something recently that threw a spanner in the works. It now returns a 500 error when you click the link. I tried it on different libraries and tenancies and same issue.
Look forward to hear from you.
Jan 19 2020 08:58 PM - edited Jan 20 2020 01:48 PM
@Aegir Brands You're correct. Looks like they've made some kind of change that is causing the '@currentWeb' reference to not load and it breaks the URL. You can instead directly call out the "preview" mode until they decide to fix this:
"href": "=if(indexOf([$ContentTypeId], '0x0120') >= 0, '?id=' + [$FileRef], [$ServerRedirectedEmbedUrl])"
Jan 19 2020 09:03 PM
@Aegir Brands There is a bug report for this issue here: https://github.com/SharePoint/sp-dev-docs/issues/5174
Jan 19 2020 10:24 PM
@AndrewFivePthanks for the quick reply. I tried your adjusted code but I get a json format error when pasting it into SharePoint json format window. Cant quite see what is causing this though.
Jan 20 2020 01:50 PM
I removed the code block and just posted raw text that doesn't include the <a> tags. That should work better.
Sep 12 2020 09:21 AM - edited Sep 13 2020 06:33 AM
You will need to protect the document to enable Viewing mode by default. Otherwise on Teams/Browser you can go to File>Info>Protect Workbook and there is a subtext: "To prevent accidental changes, this workbook has been set to open as read-only."
Sep 22 2020 06:52 AM
@AndrewFiveP This is great! Is it possible to apply this formatting to only one sub-folder of a SharePoint library? It seemingly is applying to my entire library, but I'd prefer it to apply in only one specified place.
Sep 22 2020 04:55 PM
@mharris28 Yes, it is possible with some additional conditional logic added to the code to fit your specific needs. You'll need to follow the documentation found here to achieve that: