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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / User logs out of share...
Power Apps
Unanswered

User logs out of sharepoint stops download working correctly

(0) ShareShare
ReportReport
Posted on by 17

I have made a Canvas App that is a Document Control database linking SQL and Sharepoint Library. I have a download button (it uses the '<siteurl>download.aspx?SourceUrl=<filepath>' in the url) that works fine when the user is logged in to Sharepoint, however if they log out, it doesn't work correctly.

 

The download button first alters data in a Sharepoint column for that file (using patch) and then downloads the file, however when the user logs out of sharepoint and then runs the button, the file is downloaded without the altered Sharepoint data (it has the original data). If the user selects the button again it works fine (this is because the first button press logs the user in).

 

I have worked it through and find it is due to the fact that the user has logged out (or was never logged in to Sharepoint). Is there a way to see if a user is logged in to Sharepoint from inside Power Apps?

 

You can test this with a button, add a 'launch' to your sharepoint site, if you then log out of sharepoint and select the button again, it takes you to a login screen first, otherwise it goes straight there.I guess the download url can't cope with being logged out.

 

Thanks

 

Categories:
I have the same question (0)
  • Sunil Pashikanti Profile Picture
    736 Moderator on at

    Hi @BrianWain,

     

    It seems that this is a known bug that affects the Patch function when used with SharePoint data sources. The Patch function does not update the data immediately, but rather queues the changes and applies them later. This causes the download button to fetch the old data instead of the new data.

     

    Some possible solutions are:

    • Use the SubmitForm function instead of the Patch function to update the data in SharePoint. This function will save the changes immediately and return a success or failure message.
    • Use the Refresh function after the Patch function to force the data source to reload the data from SharePoint. This function will ensure that the download button gets the latest data from the data source.
    • Use the UpdateIf function instead of the Patch function to update the data in SharePoint. This function will update only the records that match a condition, and it does not have the same delay issue as the Patch function.

     

    Best Regards,

    @SunilPashikanti 

  • BrianWain Profile Picture
    17 on at

    Hi @SunilPashikanti 

     

    Thank you for coming back to me. So I have tried your suggestions, and still have the problem that the download is fetching old data. I added a form, with the alterations to the file, the download button became the submit form and the onsuccess had the download link (with a refresh before) - still no joy. I also turned the patch to an updateif with a refresh, again no change. They all work fine if the user is already logged in to Sharepoint, but on the first attempt to download, when the user is logged out, I only get the non updated file. 

     

    Is there a way to see if the user is logged in to sharepoint from inside Power apps, if they aren't I could add a timer before the refresh, but i don't want to do this if they are already logged in?

     

    Thank you

  • Verified answer
    BrianWain Profile Picture
    17 on at

    I have stumbled across the solution. Using HttpRequest you can get a download link that works when the user is logged out of Sharepoint.

    Firstly thanks to @Reza Dorrani and his youtube video: https://www.youtube.com/watch?v=n3mhe88BI34

    From this you can get the SiteID and DriveID. I have saved them to variables: varSPSiteID and varSPDriveID

    Now the code in the download button onselect:

    Office365Groups.HttpRequest("https://graph.microsoft.com/v1.0/sites/" & varSPSiteID & "/drives/" & varSPDriveID & "/root:/" & <Encodedfilepath>, "GET", "", {ContentType: "application/json"})

     

    To get <Encodedfilepath>:

    I use the Sharepoint ‘Full Path’ of a file. (I have made a Gallery1 connect to my SharePoint Library). Unfortunately this includes the library name which I remove using the mid function, counting the characters in the name:

    Gallery1.Selected.’Full Path’ = SOPS/Forms & Templates/DEV-004 xxxx.pdf

    varSPLibraryPathLength = 6

    Mid(Gallery1.Selected.'Full Path', varSPLibraryPathLength, 500) = Forms & Templates/DEV-004 xxxx.pdf

    This then needs encoding:

    <Encodedfilepath> = EncodeUrl(Mid(Gallery1.Selected.'Full Path', varSPLibraryPathLength, 500)) =

    Forms%20%26%20Templates%2FDEV-004%20xxxx.pdf

     

    Now put the whole lot in a variable:

    Set(varSPDownload,Office365Groups.HttpRequest("https://graph.microsoft.com/v1.0/sites/" & varSPSiteID & "/drives/" & varSPDriveID & "/root:/" & EncodeUrl(Mid(Gallery1.Selected.'Full Path', varSPLibraryPathLength, 500)), "GET", "", {ContentType: "application/json"}));

     

    And then add as the next line:

    Launch(Text(varSPDownload.'@microsoft.graph.downloadUrl'))

     

    If you use the Microsoft graph alluded to in Reza’s video you can paste the output text (with the actual siteid and driveid) of the HttpRequest into that and then you can see other details you could pull out (you will see the download link):

    https://graph.microsoft.com.......Forms%20%26%20Templates%2FDEV-004%20xxxx.pdf

     

    Hopefully someone can figure this out/useful

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard