Default view mode/edit mode behavior for Word and Excel Online files

%3CLINGO-SUB%20id%3D%22lingo-sub-226287%22%20slang%3D%22en-US%22%3EDefault%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-226287%22%20slang%3D%22en-US%22%3E%3CP%3EI%20can't%20find%20the%20documentation%20for%20this%2C%20but%20I%20think%20it's%20a%20relatively%20new%20feature.%20I%20want%20my%20Word%2FExcel%2FPowerPoint%20online%20files%20to%20open%20in%20view%20mode%20instead%20of%20edit%20mode.%20When%20you%20open%20an%20Office%20Online%20file%2C%20the%20URL%20is%20like%20this%20%5Bsite%20collection%5D%2F_layouts%2F15%2FDoc.aspx%3Fsourcedoc%3D%5Bsource%20location%5D%26amp%3B%3CSTRONG%3Eaction%3C%2FSTRONG%3E%3Ddefault%26amp%3B%3CSTRONG%3Emobileredirect%3C%2FSTRONG%3E%3Dtrue%26amp%3B%3CSTRONG%3EDefaultItemOpen%3C%2FSTRONG%3E%3D1.%20The%20three%20paramtersare%20action%2C%20mobileredirect%2C%20and%20DefaultItemOpen.%26nbsp%3B%3C%2FP%3E%3CP%3EDoes%20anyone%20know%20how%20to%20change%20the%20%3CSTRONG%3Eaction%20%3C%2FSTRONG%3Eparameter%20so%20that%20its%20value%20is%20%22view%22%20instead%20of%20%22default%22%3F%20Is%20this%20set%20at%20the%20tenant%20level%2C%20or%20site%20collection%20and%2For%20library%20level%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-226287%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFiles%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESites%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-283694%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-283694%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Bynum%20Hoekstra%3C%2FP%3E%3CP%3EI%20had%20a%20bit%20of%20a%20look%20around%20and%20found%20this%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FSharePoint-Support-Blog%2FEdit-faster-in-Word-Excel-and-PowerPoint%2Fbc-p%2F283688%23M80%22%20target%3D%22_blank%22%3Eblog%20post%3C%2FA%3E%20in%20which%20some%20of%20the%20responses%26nbsp%3Bgive%20hope%20for%20a%20solution.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-283657%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-283657%22%20slang%3D%22en-US%22%3ENo%2C%20I%20haven't%20found%20out%20anything%20more.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-283652%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-283652%22%20slang%3D%22en-US%22%3E%3CP%3EI%20want%20to%20do%20this%20as%20well.%20I%20have%20trolled%20through%20all%20the%20settings%20that%20I%20could%20think%20of%20with%20no%20success.%20Were%20you%20able%20to%20find%20out%20how%20to%20do%20it%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-273087%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-273087%22%20slang%3D%22en-US%22%3E%3CP%3EI%20would%20like%20to%20be%20able%20to%20change%20this%20default%20view%20as%20well.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOn%20the%20default%20site%2C%20any%20document%20library%20opens%20the%20document%20in%20Editing%20View%2C%20but%2C%20I%20noticed%20that%20on%20a%20new%20site%20created%20with%20Microsoft%20Teams%2C%20the%20default%20view%20when%20Word%20Online%20opens%20is%20Reading%20View.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-743965%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-743965%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F239596%22%20target%3D%22_blank%22%3E%40Onno%20van%20Ewyk%3C%2FA%3E%26nbsp%3BI've%20replied%20to%20this%20blog%20post%20with%20a%20solution%20for%20this%20issue.%20Please%20see%20my%20reply%20below%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20All%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20achieve%20setting%20the%20default%20to%20'View%22%20mode%20by%20using%20SharePoint%20Column%20Formatting.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESimply%20update%20your%20column%20(in%20my%20case%20I%20updated%20Name%20to%20keep%20the%20experience%20seamless)%20with%20the%20following%20json%20and%20your%20documents%20will%20now%20open%20in%20Preview%20instead%20of%20Edit%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%7B%0A%20%20%22%24schema%22%3A%20%22https%3A%2F%2Fdeveloper.microsoft.com%2Fjson-schemas%2Fsp%2Fcolumn-formatting.schema.json%22%2C%0A%20%20%22elmType%22%3A%20%22a%22%2C%0A%20%20%22txtContent%22%3A%20%22%40currentField%22%2C%0A%20%20%22attributes%22%3A%20%7B%0A%20%20%20%20%22target%22%3A%20%22_blank%22%2C%0A%20%20%20%20%22href%22%3A%20%22%3Dif(%5B%24ContentTypeId%5D%20%3D%3D%20'0x012000D7307C77D3826F42B417802F0E0AB2AB'%2C%20'%3Fid%3D'%20%2B%20%5B%24FileRef%5D%2C%20%40currentWeb%20%2B%20'%2F_layouts%2F15%2FDoc.aspx%3Fsourcedoc%3D'%2B%20%5B%24UniqueId%5D%20%2B%20'%26amp%3Baction%3DView'%22%0A%20%20%7D%0A%7D%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20this%20does%20is%20checks%20if%20the%20item%20is%20a%20folder%20and%20uses%20existing%20behavior%20to%20open%20the%20folder%20otherwise%20it%20will%20open%20the%20document%20in%20view%20mode.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3EHope%20this%20helps%20anybody%20looking%20for%20a%20way%20to%20solve%20this%20issue!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-770422%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-770422%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F373080%22%20target%3D%22_blank%22%3E%40AndrewFiveP%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20this%20snippet!%20It%20has%20almost%20resolved%20the%20issue%20for%20me%2C%20it%20does%20open%20the%20documents%20in%20read%20only%20mode%2C%20but%20it%20also%20breaks%20the%20folders%20so%20that%20when%20a%20user%20clicks%20on%20them%20it%20opens%20a%20new%20window%20stating%20an%20error%20has%20occurred.%20It%20seems%20like%20the%20part%20that%20is%20supposed%20to%20ignore%20folders%20is%20not%20working%20correctly%2C%20but%20I%20am%20not%20familiar%20with%20JSON%20so%20I%20cannot%20change%20the%20behavior%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20there%20something%20I%20need%20to%20change%20in%20the%20JSON%20snippet%20to%20make%20it%20ignore%20folders%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-770740%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-770740%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F380990%22%20target%3D%22_blank%22%3E%40meyvazi2345%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhoops!%20Looks%20like%20you're%20right%20and%20this%20was%20too%20purpose%20built...%20I've%20updated%20the%20JSON%20in%20my%20post%20to%20reflect%20a%20wildcard%20search%20for%20the%20folder%20content%20type%20that%20works%20better%20in%20any%20situation.%3CBR%20%2F%3E%3CBR%20%2F%3ELet%20me%20know%20if%20that%20fixes%20the%20issue%20for%20you!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-770750%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-770750%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F373080%22%20target%3D%22_blank%22%3E%40AndrewFiveP%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Andrew!%20Thank%20you%20for%20replying!%20I%20just%20tested%20the%20updated%20JSON%20and%20it%20is%20still%20behaving%20the%20same%20way%2C%20the%20files%20open%20in%20view%20mode%20no%20problem%2C%20but%20the%20folders%20still%20open%20into%20an%20error%20page%20which%20I%20have%20attached.%20It%20states%20that%20the%20Object%20reference%20is%20not%20set%20to%20an%20instance%20of%20an%20object.%20Thank%20you%20again%20for%20replying%20and%20getting%20a%20solution%20out%20there%20for%20this!%20Please%20let%20me%20know%20if%20I%20can%20give%20any%20other%20information%20that%20would%20be%20helpful.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20789px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F124240i383C8E68724ACE8C%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22SharepointJSON.PNG%22%20title%3D%22SharepointJSON.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-772705%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-772705%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F380990%22%20target%3D%22_blank%22%3E%40meyvazi2345%3C%2FA%3E%26nbsp%3BOh%20dear%2C%20Im%20not%20100%25%20sure%20what%20might%20be%20occurring%20here...%20Are%20you%20using%20this%20in%20SharePoint%20online%3F%20I%20did%20find%20that%20this%20solution%20will%20struggle%20with%20folders%20that%20have%20special%20characters%20that%20will%20cause%20the%20URL%20to%20break...%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-796985%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-796985%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F373080%22%20target%3D%22_blank%22%3E%40AndrewFiveP%3C%2FA%3E%26nbsp%3BI%20find%20your%20JSON%20snippet%20very%20useful.%20Folders%20are%20handled%20properly%20as%20well%2C%20but%20images%20and%20video's%20are%20not.%20I%20guess%20it%20should%20be%20possible%20to%20add%20other%20ContentTypeID%20so%20the%20script%20uses%20standard%20behaviour%20as%20well%2C%20but%20I%20don't%20know%20how%20to%20do%20this.%20Any%20hints%3F%20Thanks.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-798737%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-798737%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F65880%22%20target%3D%22_blank%22%3E%40Martijn%20Kessels%3C%2FA%3E%26nbsp%3BCurrently%20the%20script%20simply%20treats%20anything%20other%20than%20folders%20as%20office%20documents%20so%20it%20opens%20them%20up%20in%20office%20web%20apps.%20You%20can%20add%20additional%20conditions%20for%20each%20additional%20content%20type%20and%20set%20their%20behavior%20as%20needed.%20Unfortunately%20there%20isn't%20a%20switch%20function%20so%20you'll%20need%20to%20nest%20if%20branches%20%3D%2F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1117368%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1117368%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F373080%22%20target%3D%22_blank%22%3E%40AndrewFiveP%3C%2FA%3E%26nbsp%3Bwe%20used%20your%20code%20snipped%20and%20it%20was%20working%20a%20treat.%20However%2C%20SharePoint%20must%20have%20changed%20something%20recently%20that%20threw%20a%20spanner%20in%20the%20works.%20It%20now%20returns%20a%20500%20error%20when%20you%20click%20the%20link.%20I%20tried%20it%20on%20different%20libraries%20and%20tenancies%20and%20same%20issue.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELook%20forward%20to%20hear%20from%20you.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1117412%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1117412%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F118572%22%20target%3D%22_blank%22%3E%40Aegir%20Brands%3C%2FA%3E%26nbsp%3BThere%20is%20a%20bug%20report%20for%20this%20issue%20here%3A%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2Fsp-dev-docs%2Fissues%2F5174%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2Fsp-dev-docs%2Fissues%2F5174%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1117456%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1117456%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F373080%22%20target%3D%22_blank%22%3E%40AndrewFiveP%3C%2FA%3Ethanks%20for%20the%20quick%20reply.%20I%20tried%20your%20adjusted%20code%20but%20I%20get%20a%20json%20format%20error%20when%20pasting%20it%20into%20SharePoint%20json%20format%20window.%20Cant%20quite%20see%20what%20is%20causing%20this%20though.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1117411%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1117411%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F118572%22%20target%3D%22_blank%22%3E%40Aegir%20Brands%3C%2FA%3E%26nbsp%3BYou're%20correct.%20Looks%20like%20they've%20made%20some%20kind%20of%20change%20that%20is%20causing%20the%20'%40currentWeb'%20reference%20to%20not%20load%20and%20it%20breaks%20the%20URL.%20You%20can%20instead%20directly%20call%20out%20the%20%22preview%22%20mode%20until%20they%20decide%20to%20fix%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%7B%0A%20%20%20%22%24schema%22%3A%20%22%3CA%20href%3D%22https%3A%2F%2Fdeveloper.microsoft.com%2Fjson-schemas%2Fsp%2Fcolumn-formatting.schema.json%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdeveloper.microsoft.com%2Fjson-schemas%2Fsp%2Fcolumn-formatting.schema.json%3C%2FA%3E%22%2C%0A%20%20%20%22elmType%22%3A%20%22a%22%2C%0A%20%20%20%22txtContent%22%3A%20%22%40currentField%22%2C%0A%20%20%20%22attributes%22%3A%20%7B%0A%20%20%20%20%20%20%22target%22%3A%20%22_blank%22%2C%0A%20%20%20%20%20%20%22href%22%3A%20%22%3Dif(indexOf(%5B%24ContentTypeId%5D%2C%20'0x0120')%20%26gt%3B%3D%200%2C%20'%3Fid%3D'%20%2B%20%5B%24FileRef%5D%2C%20%5B%24ServerRedirectedEmbedUrl%5D)%22%0A%20%20%20%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1118776%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1118776%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F118572%22%20target%3D%22_blank%22%3E%40Aegir%20Brands%3C%2FA%3E%26nbsp%3BThe%20code%20blocks%20in%20this%20forum%20are%20wrapping%20my%20URL%20in%20the%20json%20in%20html%20%3CA%3E%20tags%20even%20though%20the%20code%20is%20marked%20javascript%20%3D(%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20removed%20the%20code%20block%20and%20just%20posted%20raw%20text%20that%20doesn't%20include%20the%20%3CA%3E%20tags.%20That%20should%20work%20better.%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1660672%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1660672%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20will%20need%20to%20protect%20the%20document%20to%20enable%20Viewing%20mode%20by%20default.%20Otherwise%20on%20Teams%2FBrowser%20you%20can%20go%20to%20File%26gt%3BInfo%26gt%3BProtect%20Workbook%20and%20there%20is%20a%20subtext%3A%20%22To%20prevent%20accidental%20changes%2C%20this%20workbook%20has%20been%20set%20to%20open%20as%20read-only.%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1698874%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1698874%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F373080%22%20target%3D%22_blank%22%3E%40AndrewFiveP%3C%2FA%3E%26nbsp%3B%20This%20is%20great!%26nbsp%3B%20Is%20it%20possible%20to%20apply%20this%20formatting%20to%20only%20one%20sub-folder%20of%20a%20SharePoint%20library%3F%26nbsp%3B%20It%20seemingly%20is%20applying%20to%20my%20entire%20library%2C%20but%20I'd%20prefer%20it%20to%20apply%20in%20only%20one%20specified%20place.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1700540%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1700540%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F803322%22%20target%3D%22_blank%22%3E%40mharris28%3C%2FA%3E%26nbsp%3BYes%2C%20it%20is%20possible%20with%20some%20additional%20conditional%20logic%20added%20to%20the%20code%20to%20fit%20your%20specific%20needs.%20You'll%20need%20to%20follow%20the%20documentation%20found%20here%20to%20achieve%20that%3A%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fdeclarative-customization%2Fcolumn-formatting%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fdeclarative-customization%2Fcolumn-formatting%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1824470%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1824470%22%20slang%3D%22en-US%22%3E%3CP%3EFor%20anyone%20still%20running%20into%20the%20problem%2C%20I%20have%20written%20a%20Google%20Chrome%20extension%20that%20forces%20Sharepoint%20Online%20Office%20documents%20to%20be%20opened%20in%20Reading%20View%20instead%20of%20Edit%20View.%26nbsp%3B%20This%20extension%20can%20also%20be%20deployed%20via%20Group%20Policy.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20the%20Google%20Chrome%20store%2C%20search%20for%20this%20extension%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESPO%20View%20It%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fchrome.google.com%2Fwebstore%2Fdetail%2Fspo-view-it%2Fomljlibfjloccmdmmlpcnlijjneabhjm%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fchrome.google.com%2Fwebstore%2Fdetail%2Fspo-view-it%2Fomljlibfjloccmdmmlpcnlijjneabhjm%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20extension%20source%20code%20is%20also%20on%20my%20GitHub%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fjftuga%2Fspo_view_it%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fjftuga%2Fspo_view_it%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E-John%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2113986%22%20slang%3D%22en-US%22%3ERe%3A%20Default%20view%20mode%2Fedit%20mode%20behavior%20for%20Word%20and%20Excel%20Online%20files%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2113986%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F5068%22%20target%3D%22_blank%22%3E%40Bynum%20Hoekstra%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor

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?

21 Replies

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.  

 

 

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?

No, I haven't found out anything more.

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.

@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 

 

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?

 

@meyvazi2345 

 

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!

@AndrewFiveP 

 

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.

SharepointJSON.PNG

@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...

@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.

@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 =/

@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.

 

 

@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:

 

{
"$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], [$ServerRedirectedEmbedUrl])"
}
}

 

 

 

 

 

 

 

@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. 

@Aegir Brands The code blocks in this forum are wrapping my URL in the json in html <a> tags even though the code is marked javascript =(

 

I removed the code block and just posted raw text that doesn't include the <a> tags. That should work better.

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."

 

 

@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.

@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:
https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting