WebExtensions.GetAllWebUrls (PnP Core Component) – This extension method returns the collections of the URLs of all web sites that are contained within the site collection including the top-level site and its sub sites.
Supports: SharePoint 2013+, SharePoint Online
Assembly: OfficeDevPnP.Core.dll
Namespace: Microsoft.SharePoint.Client
Syntax:
Single Line Code: Site.GetAllWebUrls()
Code Snippet:
The following example returns the collection of all web sites from the Site Collection including top level site and its sub site.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.SharePoint.Client;
- using OfficeDevPnP.Core;
-
-
- namespace SampleApplication
- {
- class Program
- {
- static void Main(string[] args)
- {
- string siteUrl = "https://sharepointonline.sharepoint.com";
-
- AuthenticationManager authManager = new AuthenticationManager();
-
- var context = authManager.GetWebLoginClientContext(siteUrl);
-
- IEnumerable<string> webUrls= context.Site.GetAllWebUrls();
- string weburl = "";
- foreach(var url in webUrls)
- {
- weburl += url + "\r\n";
- }
- Console.WriteLine(weburl);
-
- Console.WriteLine("Press any key to exit.");
- Console.ReadKey();
-
- }
- }
- }