NEWS

Creating a VIEW ONLY link to SharePoint Office 365 files with Power Automate

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.

 

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


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

 {
“$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’)”
}
}

 

 

This project did not end there. The next steps were 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 Emails. 


I needed to recreate the URL using this format:

 

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

 

Step 1: Get the E Tag – 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. 

 

Looking somehting like this “{xxxxxxxxx-xxxx-xxxx-xxxxx-xxxxxxxxxxxx},1”

 

I needed to recreate the URL using this format:

https://{tenant}.sharepoint.com/:w:/r/{site}/_layouts/15/Doc.aspx?sourcedoc={File ETag}&action=ViewStep 1. Get the E Tag – 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. Looking somehting like this “{xxxxxxxxx-xxxx-xxxx-xxxxx-xxxxxxxxxxxx},1”

Step 2: Isolate the etag {} – I followed the instructions in this 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. 
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