web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Pages - General Discussions
Suggested answer

Power Pages Dataverse Table File Column - Open not download

(0) ShareShare
ReportReport
Posted on by 20
Hi All
 
I have create a page with a Dataverse table which shows a file column. The file column is hyperlinked to download (powerappsportals.com/file/download.aspx?entity......).
 
Is it possible to change this so that the file opens rather downloads?
 
New to Power Pages so some instructions and guidance would be very helpful.
 
Thanks in advance.
Categories:
I have the same question (0)
  • Suggested answer
    Jerry-IN Profile Picture
    214 on at
    Power Pages Dataverse Table File Column - Open not download
    Hello  ,

    Thanks for reaching out—it's great to see you're diving into Power Pages! By default, the hyperlink for a file column in a Dataverse list view on Power Pages is set up to trigger a download via the standard endpoint (like powerappsportals.com/file/download.aspx), but you can customize it to open compatible files (e.g., PDFs, images) directly in the browser instead. This involves a bit of JavaScript customization on the list page to intercept the link and set the appropriate HTTP headers or use browser-native viewing.
     
    Key Limitation
    Power Pages doesn't offer a built-in toggle for this behavior in list views out of the box, as file columns are primarily designed for secure downloads to protect data. However, for viewable formats like PDFs, you can achieve inline opening by modifying the link generation or using client-side scripting to force browser rendering.
     
    Step-by-Step Guidance
    Since you're new to Power Pages, I'll walk you through the process using the Portal Management app and some basic customization. This assumes your list is already set up with a Dataverse table containing the file column. We'll focus on PDFs for simplicity, as they're commonly viewed in-browser; other formats (e.g., Word docs) may require additional conversion or viewers.
    • Prepare Your Environment:
      • Open the Power Pages design studio (make.powerpages.microsoft.com) and navigate to your page with the list.
      • Ensure the list component is added and connected to your Dataverse table with the file column enabled for display.​
      • If not already done, go to Portal Management (in the classic Power Apps maker portal) > Content > Web Pages, find your list page, and note its details for later
    • Customize the List View Template (Basic Option):
      • In Portal Management, go to Content > Web Templates and create a new one (or edit the default list template).
      • Use Liquid templating to override the file column rendering. Replace the default download link with one that targets a view endpoint.
      • Example Liquid code snippet for the file column in your list template:
    {% if block.filecolumn %}
      <a href="/_api/{{ block.filecolumn | append: '?%24select=filename,value' }}" target="_blank" onclick="openFileInBrowser(event, this.href); return false;">
        {{ block.filecolumn.filename }}
      </a>
    {% endif %}
    
    • This uses the Dataverse Web API to fetch file metadata and opens in a new tab. The target="_blank" helps with browser handling.
    • Add JavaScript for Browser Opening:
      • In the design studio, select your list page > Edit code > Custom JavaScript.
      • Add this script to intercept clicks and set headers for inline viewing (e.g., for PDFs):
        function openFileInBrowser(event, url) {
          event.preventDefault();
          var xhr = new XMLHttpRequest();
          xhr.open('GET', url, true);
          xhr.setRequestHeader('Accept', 'application/pdf');  // Forces PDF to open in browser
          xhr.responseType = 'blob';
          xhr.onload = function() {
            if (xhr.status === 200) {
              var blob = new Blob([xhr.response], { type: 'application/pdf' });
              var objectUrl = URL.createObjectURL(blob);
              window.open(objectUrl, '_blank');  // Opens in new tab for viewing
            }
          };
          xhr.send();
        }
        
        This fetches the file as a blob and creates a temporary URL for the browser to render it directly, bypassing the download.​Save and sync your portal. Test by previewing the page—clicking the file link should now open PDFs in a new tab instead of downloading.
     
    • Advanced Option: Use Power Automate for Content-Type Handling:
      • If the above doesn't work for all file types, create a Power Automate cloud flow triggered by an HTTP request (from JS).
      • In the flow: Trigger > When an HTTP request is received > Add input for file ID.
      • Action: Dataverse - Get a row (by file ID) > Compose to retrieve file content > Response action with headers: Content-Type: application/pdf and Content-Disposition: inline.
      • In your JS, call the flow URL: fetch(flowUrl + '?id=' + fileId).then(response => response.blob()).then(blob => window.open(URL.createObjectURL(blob)));​​
      • This ensures the response mimics a browser-viewable file. Publish the flow and update your JS accordingly.
    • Testing and Troubleshooting:
      • Preview your portal and click a file link. For PDFs/images, it should open in the browser's native viewer; others may still download.
      • If issues arise (e.g., CORS errors), ensure your Dataverse table permissions allow anonymous or authenticated read access to files.​
      • For non-PDFs, consider integrating a PDF.js library via web files for custom rendering—upload PDF.js as a static file in Portal Management > Web Files, then reference it in JS.​
      • Debug in browser console (F12) for errors. If you're dealing with large files, add loading indicators to the JS.
    This should get you up and running without too much hassle. If your files include non-PDF types or you hit a snag, feel free to share more details about the table/file types for tailored tweaks. Power Pages customizations like this build your skills quickly!
     
    Best Regards,
    Jerald Felix
     
  • SliderUK Profile Picture
    20 on at
    Power Pages Dataverse Table File Column - Open not download
    Thanks for the detailed message.
     
    Having a bit of trouble getting it working though. Here is what I've done so far.
     
    Created a new Web Template
    Created a new Page Template - copied the code in the page template that my page is using and added the liquid code you sent.
    Gone to my Web Page and reampped the page template to this new one I just created.
    Gone to the web page in Editor and added the custom javascript.
     
    The javascript does exist having checked (F12) but the links remain the same. Would liquid code errors show in F12?
     
    Also wanted to check filecolumn is actually the column name or is just still filecolumn? I tried both didnt but didnt work.
     
    Not sure if it makes a difference but the page is actually a Form with subgrids pointing to related views of the dataverse table which show the files.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Pages

#1
Fubar Profile Picture

Fubar 50 Super User 2025 Season 2

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 38 Super User 2025 Season 2

#3
Jerry-IN Profile Picture

Jerry-IN 30

Last 30 days Overall leaderboard