Forum Discussion
Sharepoint Authentication fails when using Web.Contents with RelativePath on files
- 1 year ago
Hi AlexR_DE,
Thank you for the follow-up and for clearly outlining the issue. You are right to be concerned about performance when dealing with a large number of files in a SharePoint document library.
To avoid the performance overhead of scanning all files in the folder (as is the default
behaviour with SharePoint.Files), and since you already know the exact file path, you can directly access the file using either:
Option1: SharePoint.Contents() with direct file targeting.
This method allows you to retrieve a specific file from the library without pulling metadata for all other files:let SiteURL = "https://yourtenant.sharepoint.com/sites/yoursite/", FilePath = "Shared Documents/FolderName/YourFile.xlsx", File = SharePoint.Contents(SiteURL){[Name="YourFile.xlsx", FolderPath=SiteURL & "Shared Documents/FolderName/"]}[Content], ExcelData = Excel.Workbook(File) in ExcelData
Option2: Web.Contents() for direct file access.
Alternatively, use Web.Contents() if you have a static link to the file:let FileURL = "https://yourtenant.sharepoint.com/sites/yoursite/Shared%20Documents/FolderName/YourFile.xlsx", Source = Excel.Workbook(Web.Contents(FileURL)) in Source
Make sure that the authentication method in Data Source Settings is set to Organizational Account.If you are using Power BI Service, confirm that the SharePoint connector is configured using OAuth in the dataset settings, especially if the file is protected under Microsoft 365 authentication policies.
Hope this helps clarify things and let me know what you find after giving these steps a try happy to help you investigate this further.
Thank you for using the Microsoft Community Forum.
Hi AlexR_DE ,
Is there a specific reason you're not using the SharePoint Folder connector? It's designed to do exactly what it appears you're trying to achieve.
Power Query SharePoint folder connector - Power Query | Microsoft Learn
Pete
- AlexR_DE1 year agoFrequent Visitor
Yes, I am using a custom REST query to extract all files, because I expect loads of files (10.000+) in that folder and that will not work with the connector in a performing way...