Converting Shared Folder URL to an Un-Shortened URL

Anand Shende 1 Reputation point
2021-11-29T13:29:48.89+00:00

Hi,

I want to integrate with the Subscription API of Sharepoint. I want to Subscribe to a particular Folder using the Shared Folder URL.

In order Subscribe, I will need the following:

  1. Site URL
  2. List Name/Title
  3. Folder Path

I have been able to extract the Site URL from the Shared Folder URL using the API (https://pnp.github.io/pnpjs/sp/sites/#get-site-collection-url-from-page).

The Problem
Shared Folder URL Link is of the form https://{Vendor}.sharepoint.com/:f:/s/{Site_Name}/{Random_ID}?e={Random_Value}
There is no API that I have come across which can help me extract the other items (List Name & Folder Path).

Please help me with this query, thanks.

Microsoft 365 and Office SharePoint Development
Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2021-11-30T02:36:48.937+00:00

    Hi @Anand Shende ,
    I will recommend you rest api to get List Name and Folder Path. Please refer to the following url.

    https://xxxx.sharepoint.com/sites/xxx/_api/web/GetFolderByServerRelativeUrl('Document%20Lib/test')?$select=ServerRelativeUrl,Name  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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.



  2. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2021-12-03T07:43:02.493+00:00

    Hi @Anand Shende ,
    You can refer to the following code to get Share Link.

    import { sp } from "@pnp/sp";  
    import "@pnp/sp/webs";  
    import "@pnp/sp/sharing";  
    import { SharingLinkKind, IShareLinkResponse } from "@pnp/sp/sharing";  
    import { dateAdd } from "@pnp/common";  
      
    const result = await sp.web.getFolderByServerRelativeUrl("/sites/dev/Shared Documents/folder1").getShareLink(SharingLinkKind.AnonymousView);  
      
    console.log(JSON.stringify(result, null, 2));  
      
      
    const result2 = await sp.web.getFolderByServerRelativeUrl("/sites/dev/Shared Documents/folder1").getShareLink(SharingLinkKind.AnonymousView, dateAdd(new Date(), "day", 5));  
      
    console.log(JSON.stringify(result2, null, 2));  
    

    Here is the document
    https://pnp.github.io/pnpjs/sp/sharing/#sharewith


Your answer

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