title: Extracting folder/sub folder name from SharePoint document library URL
body: <p>I'm newbie to Sharepoint and currently using Sharepoint Online. I'm in need of retrieving files under a sharepoint document library in C#.</p>
  
  <p>We have couple of document library urls as follows:</p>
  
  <ol>
  <li><a href="https://customer1.sharepoint.com/" rel="nofollow noreferrer">https://customer1.sharepoint.com/</a><strong>DocumentFolder</strong>/Forms/AllItems.aspx</li>
  <li><a href="https://customer2.sharepoint.com/sites/" rel="nofollow noreferrer">https://customer2.sharepoint.com/sites/</a><strong>sitename</strong>/<strong>DocumentFolder</strong>/<strong>SubFolder</strong>/Forms/AllItems.aspx</li>
  </ol>
  
  <p>I need to extract <strong>DocumentFolder</strong> name in case of URL 1 above, and <strong>DocumentFolder</strong>/<strong>SubFolder</strong> name in case of URL 2</p>
  
  <p>Using <a href="https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest" rel="nofollow noreferrer">Sharepoint REST</a> service, I then would like to list files under <strong>DocumentFolder</strong> :</p>
  
  <p><a href="http://site" rel="nofollow noreferrer">http://site</a> url/_api/web/GetFolderByServerRelativeUrl('/<strong>DocumentFolder</strong>') </p>
  
  <p>The challenge I have is to extract the <strong>DocumentFolder</strong> for the above URLs, as I could not find any API/method call to extract the <strong>DocumentFolder</strong>. I could try regex on the url, but it'll be helpful, if there is a right way to extract the <strong>DocumentFolder</strong>/SubFolder, that will be helpful.</p>