Pass folder name via URL to SPO Rest API call

sp13test 281 Reputation points
2021-02-03T06:13:03.057+00:00

I have one page listing different folder URLs. Clicking the link should trigger the code below on the second page using parameters passed from the URL from page one.

I am trying to pass Folder name parameter via URL to load the API call in custom ASPX page on SPO. The URL linking to this second page code below will have the folder details.

URL format from page one - <<<SPO_SITE>>>/SiteAssets/Image.aspx?Folder="<<<FOLDER_NAME>>>"

63384-snipaste.png

Thanks for any help please.

Microsoft 365 and Office | SharePoint Server | Development
0 comments No comments
{count} votes

Answer accepted by question author
  1. ZhengyuGuo 10,591 Reputation points Moderator
    2021-02-04T06:04:15.263+00:00

    Hi @sp13test ,

    Try to get the Folder querystring parameter in the url and pass into Rest EndPoint like this:

    var relativeurl = "/sites/dev/Share Documents/" + GetParameterValues("Folder");  
    var requestUri = _spPageContextInfo.webAbsoluteUrl +"/_api/web/getfolderbyserverrelativeurl('"+relativeurl+"')/Files?$top=2000&$select=ServerRelativeUrl";  
      
      
    function GetParameterValues(param) {  
                var url = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');  
                for (var i = 0; i < url.length; i++) {  
                    var urlparam = url[i].split('=');  
                    if (urlparam[0] == param) {  
                        return urlparam[1];  
                    }  
                }  
            }  
    

    Thanks
    Best Regards


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.