Make a list of all sites in a site collection
-
08-02-2021 - |
Domanda
Is it possible to obtain a list of all sites in the site collection, such that it can be used e.g. in a lookup column?
So far I have found two ways of getting a display of my sites:
- Opening Site settings and then Site hierarchy on the top level site.
- Adding a content search webpart with a custom query (as described here).
While these methods are good ways to have a look at your site collection, I need a way to put together a sharepoint list for further use in workflows etc. How can that be archieved?
I am a site collection administrator and my company is running SP 2013 on premise.
Thank you for your help
Soluzione
You can use the following REST API call to get a "list of lists" on your site.
https://{site_url}/_api/web/lists
To get a list of subsites within the current Site Collection, do:
https://{site_url}/_api/web/webs
To get a list of all sites in the environment, use the Search functions of the API, the following query gets all site collections and all subsites:
https://{site_url}/_api/search/query?
querytext='contentclass:STS_Site contentclass:STS_Web'
&selectproperties='Title,Path'
If you just want to get top-level site collections without the subsites, just omit the contentclass:STS_Web
.
If you have Workflow Services installed in order to create a workflow that uses the 2013 Workflow engine (as opposed the 2010 engine that is still the default in SP2013), then you can call this service directly from your workflow.