View Only

Creating a VIEW ONLY link to SharePoint Office 365 files

Opening files in SharePoint online, all files open in edit mode. This is great when they are your files, but what if I only want to review a document. The view mode is much more desirable. So I set out to find the solution to opening files from a document library in view mode by default.

[nbsp_tc]

This is easy enough to do within the document library using JSON formatting in the column.[nbsp_tc]

[br_tc]I am no JSON expert, so I was able to find this solution here.

[nbsp_tc]{[br_tc]”$schema”: “https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json”,[br_tc]”elmType”: “a”,[br_tc]”txtContent”: “@currentField”,[br_tc]”attributes”: {[br_tc]”target”: “_blank”,[br_tc]”href”: “=if(indexOf([$ContentTypeId], ‘0x0120’) >= 0, ‘?id=’ + [$FileRef], @currentWeb + ‘/_layouts/15/Doc.aspx?sourcedoc=’+ [$UniqueId] + ‘&action=View’)”[br_tc]}[br_tc]}

[nbsp_tc]

[nbsp_tc]

This project did not end there. The next steps were[nbsp_tc]linking to the file from PowerApps. By default the link to item opens in edit mode. So now I was able to combine the following blog posts to come up with a solution to generate a sharing link that I used in PowerApps and[nbsp_tc]Emails.[nbsp_tc]

[br_tc]I needed to recreate the URL using this format:

[nbsp_tc]

https://{tenant}.sharepoint.com/:w:/r/{site}/_layouts/15/Doc.aspx?sourcedoc={File[nbsp_tc]ETag}&action=View

[nbsp_tc]

Step 1: Get the E Tag -[nbsp_tc]In Power Automate (Flow), the etag property is available, but it has a comma and number at the end. Now what we needed was to remove the parts of the property we didn’t need.[nbsp_tc]

[nbsp_tc]

Looking somehting like this[nbsp_tc]”{xxxxxxxxx-xxxx-xxxx-xxxxx-xxxxxxxxxxxx},1″

[nbsp_tc]

I needed to recreate the URL using this format:

https://{tenant}.sharepoint.com/:w:/r/{site}/_layouts/15/Doc.aspx?sourcedoc={File[nbsp_tc]ETag}&action=ViewStep 1. Get the E Tag -[nbsp_tc]In Power Automate (Flow) the etag property is available but it has a comma and number at the end. Now what we needed was to remove the parts of the property we didnt need.[nbsp_tc]Looking somehting like this[nbsp_tc]”{xxxxxxxxx-xxxx-xxxx-xxxxx-xxxxxxxxxxxx},1″

Step 2: Isolate the etag {} – I[nbsp_tc]followed the instructions in[nbsp_tc]this[nbsp_tc]support post

Add a Compose action, Inputs set to following formula:

add(indexOf(triggerBody()?[‘ETag’],'{‘),1)

Add a Compose 2 action, Inputs set to following formula:

indexOf(triggerBody()?[‘ETag’],’}’)

Add a Compose 3 action, Inputs set to following formula:

sub(outputs(‘Compose_2’),outputs(‘Compose’))

Add a Compose 4 action, Inputs set to following formula:

substring(triggerBody()?[‘ETag’],outputs(‘Compose’),outputs(‘Compose_3’))

Step 3: Create the Sharing Link

Since I was using this link in several places, I decided to create a column on the file properties to hold this link was generated.[nbsp_tc][br_tc]Update File Properties – Sharing Link Column

You will need to update your Compose 4 Output with the variable in Power Automate.

https://{tenant}.sharepoint.com/:w:/r/{site}/_layouts/15/Doc.aspx?sourcedoc={{Compose4 Output}}&action=View​

Klarinet Solutions specializes in enhancing system performance, optimizing user experience, and developing a streamlined process supporting business objectives. To find out more about our services or help with O365 PowerApps or Power Automate. Feel free to contact our solutions-delivery team or reach us by phone at (866) 211-8191.

Share this page

Leave a Reply