: Seamlessly Open SharePoint Attachments from Power Apps Canvas App

 

✅ Overview

This guide walks you through every step needed to add an “Open Attachment” button inside your Canvas app gallery. It fetches the first attachment from SharePoint (list visio2) via Power Automate and opens it directly in the browser in preview mode.


๐Ÿ”ธ Step 1: Configure SharePoint for Attachments

  • Go to your visio2 SharePoint list.

  • Select List Settings → Advanced Settings.

  • Ensure Attachments are set to Yes.

  • Save changes.


๐Ÿ”„ Step 2: Create Power Automate Flow – GetVisio2AttachmentUrl

  1. In Power Automate, click Create → Instant cloud flow.

  2. Name it GetVisio2AttachmentUrl and select Power Apps (V2) trigger.

  3. Click + Add an input, select Number, and rename it to itemID.

  4. Get item Action:

    • Site: your SharePoint site

    • List: visio2

    • ID: choose itemID from trigger inputs

  5. Get attachments Action:

    • Site: same as above

    • List: visio2

    • ID: still itemID

  6. Compose Action:

    • Expression:

      text
      first(body('Get_attachments'))?['AbsoluteUri']
  7. Respond to a Power App or flow Action:

    • Click + Add output → Text

    • Name it AttachmentUrl

    • Value: Outputs from Compose

  8. Click Save.


๐Ÿ–ฅ️ Step 3: Build the Canvas App

  1. Open Power Apps Studio and add data source: SharePoint → visio2.

  2. Insert a Vertical Gallery, set Items = visio2.

  3. Within the gallery template, insert a Button and label it Open Attachment.

  4. On the Action tab, click Power Automate and add your flow GetVisio2AttachmentUrl.


✏️ Step 4: Add the Correct Button Formula

Paste this exact code into the button’s OnSelect property:

powerapps
// 1⃣ Call the flow with the item’s ID as a number Set( varResult, GetVisio2AttachmentUrl.Run(Value(ThisItem.ID)) ); // 2⃣ Extract the attachment URL from the returned record Set( varUrl, varResult.AttachmentUrl ); // 3⃣ Launch the file in browser if URL is available If( !IsBlank(varUrl), Launch(varUrl & "?web=1") )

Explanation:

  • Value(ThisItem.ID): Ensures numeric type matches input.

  • varResult: Holds the record returned by the flow.

  • varResult.AttachmentUrl: Retrieves the URL stored in the record.

  • Launch(...): Opens the file in the browser with ?web=1 to enable preview.


๐Ÿ” Step 5: Save, Publish & Test

  1. Save your app and click Publish.

  2. Enter Preview Mode (F5).

  3. Click Open Attachment on a gallery item — it should open the first attachment in a new browser tab!

Comments

Popular posts from this blog

Bridging the Impossible: Connecting Jira On-Prem to Power Automate & Copilot Studio — The Solution Nobody Built Until Now"

How I Automated My Entire SharePoint Tenant with 150 MCP Tools and Claude Desktop

Azure Management MCP Server