Class TenantExtensions
Class for tenant extension methods
Inheritance
Namespace: Microsoft.SharePoint.Client
Assembly: PnP.Framework.dll
Syntax
public static class TenantExtensions : object
Methods
AddAdministrators(Tenant, IEnumerable<UserEntity>, Uri, Boolean)
Add a site collection administrator to a site collection
Declaration
public static void AddAdministrators(this Tenant tenant, IEnumerable<UserEntity> adminLogins, Uri siteUrl, bool addToOwnersGroup = false)
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
IEnumerable<UserEntity>
adminLogins
Array of admins loginnames to add |
Uri
siteUrl
Url of the site to operate on |
System.Boolean
addToOwnersGroup
Optionally the added admins can also be added to the Site owners group |
ApplyProvisionHierarchy(Tenant, ProvisioningHierarchy, String, ProvisioningTemplateApplyingInformation)
Declaration
public static void ApplyProvisionHierarchy(this Tenant tenant, ProvisioningHierarchy hierarchy, string sequenceId, ProvisioningTemplateApplyingInformation applyingInformation = null)
Parameters
Tenant
tenant
|
ProvisioningHierarchy
hierarchy
|
System.String
sequenceId
|
ProvisioningTemplateApplyingInformation
applyingInformation
|
ApplyTenantTemplate(Tenant, ProvisioningHierarchy, String, ApplyConfiguration)
Applies a template to a tenant
Declaration
public static void ApplyTenantTemplate(this Tenant tenant, ProvisioningHierarchy tenantTemplate, string sequenceId, ApplyConfiguration configuration = null)
Parameters
Tenant
tenant
|
ProvisioningHierarchy
tenantTemplate
|
System.String
sequenceId
|
ApplyConfiguration
configuration
|
CheckIfSiteExists(Tenant, String, String)
Returns if a site collection is in a particular status. If the URL contains a sub site then returns true is the sub site exists, false if not. Status is irrelevant for sub sites
Declaration
public static bool CheckIfSiteExists(this Tenant tenant, string siteFullUrl, string status)
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
System.String
siteFullUrl
Url to the site collection |
System.String
status
Status to check (Active, Creating, Recycled) |
Returns
System.Boolean
True if in status, false if not in status |
CreateSiteCollection(Tenant, SiteEntity, Boolean, Boolean, Func<TenantOperationMessage, Boolean>)
Adds a SiteEntity by launching site collection creation and waits for the creation to finish
Declaration
public static Guid CreateSiteCollection(this Tenant tenant, SiteEntity properties, bool removeFromRecycleBin = false, bool wait = true, Func<TenantOperationMessage, bool> timeoutFunction = null)
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
SiteEntity
properties
Describes the site collection to be created |
System.Boolean
removeFromRecycleBin
It true and site is present in recycle bin, it will be removed first from the recycle bin |
System.Boolean
wait
If true, processing will halt until the site collection has been created |
Func<TenantOperationMessage, System.Boolean>
timeoutFunction
An optional function that will be called while waiting for the site to be created. If set will override the wait variable. Return true to cancel the wait loop. |
Returns
Guid
Guid of the created site collection and Guid.Empty is the wait parameter is specified as false. Returns Guid.Empty if the wait is cancelled. |
CreateSiteCollection(Tenant, String, String, String, String, Int32, Int32, Int32, Int32, Int32, UInt32, Boolean, Boolean, Func<TenantOperationMessage, Boolean>)
Launches a site collection creation and waits for the creation to finish
Declaration
public static Guid CreateSiteCollection(this Tenant tenant, string siteFullUrl, string title, string siteOwnerLogin, string template, int storageMaximumLevel, int storageWarningLevel, int timeZoneId, int userCodeMaximumLevel, int userCodeWarningLevel, uint lcid, bool removeFromRecycleBin = false, bool wait = true, Func<TenantOperationMessage, bool> timeoutFunction = null)
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
System.String
siteFullUrl
The SPO URL |
System.String
title
The site title |
System.String
siteOwnerLogin
Owner account |
System.String
template
Site template being used |
System.Int32
storageMaximumLevel
Site quota in MB |
System.Int32
storageWarningLevel
Site quota warning level in MB |
System.Int32
timeZoneId
TimeZoneID for the site. "(UTC+01:00) Brussels, Copenhagen, Madrid, Paris" = 3 |
System.Int32
userCodeMaximumLevel
The user code quota in points |
System.Int32
userCodeWarningLevel
The user code quota warning level in points |
System.UInt32
lcid
The site locale. See http://technet.microsoft.com/en-us/library/ff463597.aspx for a complete list of Lcid's |
System.Boolean
removeFromRecycleBin
If true, any existing site with the same URL will be removed from the recycle bin |
System.Boolean
wait
Wait for the site to be created before continuing processing |
Func<TenantOperationMessage, System.Boolean>
timeoutFunction
An optional function that will be called while waiting for the site to be created. If set will override the wait variable. Return true to cancel the wait loop. |
Returns
Guid
Guid of the created site collection and Guid.Empty is the wait parameter is specified as false. Returns Guid.Empty if the wait is cancelled. |
DeleteSiteCollection(Tenant, String, Boolean, Func<TenantOperationMessage, Boolean>)
Deletes a site collection
Declaration
public static bool DeleteSiteCollection(this Tenant tenant, string siteFullUrl, bool useRecycleBin, Func<TenantOperationMessage, bool> timeoutFunction = null)
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
System.String
siteFullUrl
Url of the site collection to delete |
System.Boolean
useRecycleBin
Leave the deleted site collection in the site collection recycle bin |
Func<TenantOperationMessage, System.Boolean>
timeoutFunction
An optional function that will be called while waiting for the site to be created. Return true to cancel the wait loop. |
Returns
System.Boolean
True if deleted |
DeleteSiteCollectionFromRecycleBin(Tenant, String, Boolean, Func<TenantOperationMessage, Boolean>)
Deletes a site collection from the site collection recycle bin
Declaration
public static bool DeleteSiteCollectionFromRecycleBin(this Tenant tenant, string siteFullUrl, bool wait = true, Func<TenantOperationMessage, bool> timeoutFunction = null)
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
System.String
siteFullUrl
URL of the site collection to delete |
System.Boolean
wait
If true, processing will halt until the site collection has been deleted from the recycle bin |
Func<TenantOperationMessage, System.Boolean>
timeoutFunction
An optional function that will be called while waiting for the site to be created. If set will override the wait variable. Return true to cancel the wait loop. |
Returns
System.Boolean
|
DisableSiteClassifications(Tenant, String)
Disables Site Classifications settings for the target tenant
Declaration
public static void DisableSiteClassifications(this Tenant tenant, string accessToken)
Parameters
Tenant
tenant
The target tenant |
System.String
accessToken
The OAuth accessToken for Microsoft Graph with Azure AD |
EnableCommSite(Tenant, String)
Enable communication site on the root site of a tenant
Declaration
public static void EnableCommSite(this Tenant tenant, string siteUrl = "")
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
System.String
siteUrl
Root site url of your tenant |
EnableCommunicationSite(Tenant, String)
Enable communication site on the root site of a tenant
Declaration
public static void EnableCommunicationSite(this Tenant tenant, string siteUrl = "")
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
System.String
siteUrl
Root site url of your tenant |
EnableSiteClassifications(Tenant, String, IEnumerable<String>, String, String)
Enables Site Classifications for the target tenant
Declaration
public static void EnableSiteClassifications(this Tenant tenant, string accessToken, IEnumerable<string> classificationsList, string defaultClassification = "", string usageGuidelinesUrl = "")
Parameters
Tenant
tenant
The target tenant |
System.String
accessToken
The OAuth accessToken for Microsoft Graph with Azure AD |
IEnumerable<System.String>
classificationsList
The list of classification values |
System.String
defaultClassification
The default classification |
System.String
usageGuidelinesUrl
The URL of a guidance page |
EnableSiteClassifications(Tenant, String, SiteClassificationsSettings)
Enables Site Classifications for the target tenant
Declaration
public static void EnableSiteClassifications(this Tenant tenant, string accessToken, SiteClassificationsSettings siteClassificationsSettings)
Parameters
Tenant
tenant
The target tenant |
System.String
accessToken
The OAuth accessToken for Microsoft Graph with Azure AD |
SiteClassificationsSettings
siteClassificationsSettings
The site classifications settings to apply. |
EnsureAppCatalogAsync(Tenant, String, String, Int32, Boolean)
Creates a new App Catalog and registers the app catalog site as the tenant App Catalog.
Declaration
public static async Task EnsureAppCatalogAsync(this Tenant tenant, string url, string ownerLogin, int timeZoneId, bool force = false)
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
System.String
url
The Full Site Url, e.g. https://yourtenant.sharepoint.com/sites/appcatalog |
System.String
ownerLogin
The username of the owner of the appcatalog, e.g. user@domain.com |
System.Int32
timeZoneId
TimeZoneId for the appcatalog site. "(UTC+01:00) Brussels, Copenhagen, Madrid, Paris" = 3" |
System.Boolean
force
If true, and an appcatalog is already registered and present, the new appcatalog will be created. If the same URL is provided and the site is present the current one will be deleted and a new one will be created. |
Returns
Task
|
GetAppCatalog(Tenant)
Gets the Uri for the tenant's app catalog site (if that one has already been created)
Declaration
public static Uri GetAppCatalog(this Tenant tenant)
Parameters
Tenant
tenant
Tenant to operate against |
Returns
Uri
The Uri holding the app catalog site URL |
GetHubSiteChildUrls(Tenant, Guid, String)
Returns the urls of sites connected to the hubsite specified
Declaration
public static List<string> GetHubSiteChildUrls(this Tenant tenant, Guid hubsiteId, string tenantAdminUrl = null)
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
Guid
hubsiteId
The id of the hubsite |
System.String
tenantAdminUrl
The URL to use to connect to the tenant admin site. Typically only provided in the case of a vanity domain tenant. If not provided, tenant-admin will be assumed. |
Returns
List<System.String>
|
GetHubSiteChildUrls(Tenant, String, String)
Returns the urls of sites connected to the hubsite specified
Declaration
public static List<string> GetHubSiteChildUrls(this Tenant tenant, string hubSiteUrl, string tenantAdminUrl = null)
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
System.String
hubSiteUrl
The fully qualified url of the hubsite |
System.String
tenantAdminUrl
The URL to use to connect to the tenant admin site. Typically only provided in the case of a vanity domain tenant. If not provided, tenant-admin will be assumed. |
Returns
List<System.String>
|
GetSiteClassificationsSettings(Tenant, String)
Enables Site Classifications for the target tenant
Declaration
public static SiteClassificationsSettings GetSiteClassificationsSettings(this Tenant tenant, string accessToken)
Parameters
Tenant
tenant
The target tenant |
System.String
accessToken
The OAuth accessToken for Microsoft Graph with Azure AD |
Returns
SiteClassificationsSettings
The list of Site Classifications values |
GetSiteCollections(Tenant, Int32, Int32, Boolean, Boolean)
Returns all site collections in the current Tenant based on a startIndex. IncludeDetail adds additional properties to the SPSite object.
Declaration
public static IList<SiteEntity> GetSiteCollections(this Tenant tenant, int startIndex = 0, int endIndex = 500000, bool includeDetail = true, bool includeOD4BSites = false)
Parameters
Tenant
tenant
Tenant object to operate against |
System.Int32
startIndex
Not relevant anymore |
System.Int32
endIndex
Not relevant anymore |
System.Boolean
includeDetail
Option to return a limited set of data |
System.Boolean
includeOD4BSites
Also return the OD4B sites |
Returns
IList<SiteEntity>
An IList of SiteEntity objects |
GetSiteGuidByUrl(Tenant, String)
Gets the ID of site collection with specified URL
Declaration
public static Guid GetSiteGuidByUrl(this Tenant tenant, string siteFullUrl)
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
System.String
siteFullUrl
A URL that specifies a site collection to get ID. |
Returns
Guid
The Guid of a site collection |
GetSiteGuidByUrl(Tenant, Uri)
Gets the ID of site collection with specified URL
Declaration
public static Guid GetSiteGuidByUrl(this Tenant tenant, Uri siteFullUrl)
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
Uri
siteFullUrl
A URL that specifies a site collection to get ID. |
Returns
Guid
The Guid of a site collection or an Guid.Empty if the Site does not exist |
GetSitePropertiesById(Tenant, Guid, Boolean, String)
Returns details of a site collection by its site collection Id
Declaration
public static SiteProperties GetSitePropertiesById(this Tenant tenant, Guid siteId, bool detailed = true, string tenantAdminUrl = null)
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
Guid
siteId
The id of the site collection |
System.Boolean
detailed
Boolean indicating if detailed information should be returned of the site (true - default) or only the basics (false) |
System.String
tenantAdminUrl
The URL to use to connect to the tenant admin site. Typically only provided in the case of a vanity domain tenant. If not provided, tenant-admin will be assumed. |
Returns
SiteProperties
SiteProperties of the site collection or NULL of no site collection found with the provided Id |
GetTenantIdByUrl(String, AzureEnvironment)
Declaration
public static string GetTenantIdByUrl(string tenantUrl, AzureEnvironment azureEnvironment = default(AzureEnvironment))
Parameters
System.String
tenantUrl
|
AzureEnvironment
azureEnvironment
|
Returns
System.String
|
GetTenantRootSiteUrl(Tenant)
Declaration
public static string GetTenantRootSiteUrl(this Tenant tenant)
Parameters
Tenant
tenant
|
Returns
System.String
|
GetTenantTemplate(Tenant, ExtractConfiguration)
Extracts a template from a tenant
Declaration
public static ProvisioningHierarchy GetTenantTemplate(this Tenant tenant, ExtractConfiguration configuration)
Parameters
Tenant
tenant
|
ExtractConfiguration
configuration
|
Returns
ProvisioningHierarchy
|
GetWebTemplates(Tenant, UInt32, Int32)
Returns available webtemplates/site definitions
Declaration
public static SPOTenantWebTemplateCollection GetWebTemplates(this Tenant tenant, uint lcid, int compatibilityLevel)
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
System.UInt32
lcid
Locale identifier (LCID) for the language |
System.Int32
compatibilityLevel
14 for SharePoint 2010, 15 for SharePoint 2013/SharePoint Online |
Returns
SPOTenantWebTemplateCollection
Returns collection of SPTenantWebTemplate |
GroupifySite(Tenant, String, TeamSiteCollectionGroupifyInformation)
Connect an Office 365 group to an existing SharePoint site collection
Declaration
public static void GroupifySite(this Tenant tenant, string siteUrl, TeamSiteCollectionGroupifyInformation siteCollectionGroupifyInformation)
Parameters
Tenant
tenant
The target tenant |
System.String
siteUrl
Url to the site collection that needs to get connected to an Office 365 group |
TeamSiteCollectionGroupifyInformation
siteCollectionGroupifyInformation
Information that configures the "groupify" process |
IsCurrentUserTenantAdmin(ClientContext)
Returns if the current user is a tenant administrator
Declaration
public static bool IsCurrentUserTenantAdmin(ClientContext clientContext)
Parameters
ClientContext
clientContext
|
Returns
System.Boolean
|
IsCurrentUserTenantAdmin(ClientContext, String)
Declaration
public static bool IsCurrentUserTenantAdmin(ClientContext clientContext, string tenantAdminSiteUrl)
Parameters
ClientContext
clientContext
|
System.String
tenantAdminSiteUrl
|
Returns
System.Boolean
|
IsSiteActive(Tenant, String)
Checks if a site collection is Active
Declaration
public static bool IsSiteActive(this Tenant tenant, string siteFullUrl)
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
System.String
siteFullUrl
URL to the site collection |
Returns
System.Boolean
True if active, false if not |
SetSiteLockState(Tenant, String, SiteLockState, Boolean, Func<TenantOperationMessage, Boolean>)
Sets a site to Unlock access or NoAccess. This operation may occur immediately, but the site lock may take a short while before it goes into effect.
Declaration
public static void SetSiteLockState(this Tenant tenant, string siteFullUrl, SiteLockState lockState, bool wait = false, Func<TenantOperationMessage, bool> timeoutFunction = null)
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site (i.e. https://[tenant]-admin.sharepoint.com) |
System.String
siteFullUrl
The target site to change the lock state. |
SiteLockState
lockState
The target state the site should be changed to. |
System.Boolean
wait
If true, processing will halt until the site collection lock state has been implemented |
Func<TenantOperationMessage, System.Boolean>
timeoutFunction
An optional function that will be called while waiting for the site to be created. If set will override the wait variable. Return true to cancel the wait loop. |
SetSiteProperties(Tenant, String, String, Nullable<Boolean>, Nullable<SharingCapabilities>, Nullable<Int64>, Nullable<Int64>, Nullable<Double>, Nullable<Double>, Nullable<Boolean>, Nullable<Boolean>, Nullable<Boolean>, Nullable<Online.SharePoint.TenantManagement.SharingPermissionType>, Nullable<Online.SharePoint.TenantManagement.SharingLinkType>, Boolean, Func<TenantOperationMessage, Boolean>)
Sets tenant site Properties
Declaration
public static void SetSiteProperties(this Tenant tenant, string siteFullUrl, string title = null, bool? allowSelfServiceUpgrade = null, SharingCapabilities? sharingCapability = null, long? storageMaximumLevel = null, long? storageWarningLevel = null, double? userCodeMaximumLevel = null, double? userCodeWarningLevel = null, bool? noScriptSite = null, bool? commentsOnSitePagesDisabled = null, bool? socialBarOnSitePagesDisabled = null, Online.SharePoint.TenantManagement.SharingPermissionType? defaultLinkPermission = null, Online.SharePoint.TenantManagement.SharingLinkType? defaultSharingLinkType = null, bool wait = true, Func<TenantOperationMessage, bool> timeoutFunction = null)
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
System.String
siteFullUrl
full URL of site |
System.String
title
site title |
System.Nullable<System.Boolean>
allowSelfServiceUpgrade
Boolean value to allow serlf service upgrade |
System.Nullable<SharingCapabilities>
sharingCapability
SharingCapabilities enumeration value (i.e. Disabled/ExternalUserSharingOnly/ExternalUserAndGuestSharing/ExistingExternalUserSharingOnly) |
System.Nullable<System.Int64>
storageMaximumLevel
A limit on all disk space used by the site collection |
System.Nullable<System.Int64>
storageWarningLevel
A storage warning level for when administrators of the site collection receive advance notice before available storage is expended. |
System.Nullable<System.Double>
userCodeMaximumLevel
A value that represents the maximum allowed resource usage for the site/ |
System.Nullable<System.Double>
userCodeWarningLevel
A value that determines the level of resource usage at which a warning e-mail message is sent |
System.Nullable<System.Boolean>
noScriptSite
Boolean value which allows to customize the site using scripts |
System.Nullable<System.Boolean>
commentsOnSitePagesDisabled
Boolean value which Enables/Disables comments on the Site Pages |
System.Nullable<System.Boolean>
socialBarOnSitePagesDisabled
Boolean value which Enables/Disables likes and view count on the Site Pages |
System.Nullable<Microsoft.Online.SharePoint.TenantManagement.SharingPermissionType>
defaultLinkPermission
Specifies the default link permission for the site collection |
System.Nullable<Microsoft.Online.SharePoint.TenantManagement.SharingLinkType>
defaultSharingLinkType
Specifies the default link type for the site collection |
System.Boolean
wait
Id true this function only returns when the tenant properties are set, if false it will return immediately |
Func<TenantOperationMessage, System.Boolean>
timeoutFunction
An optional function that will be called while waiting for the tenant properties to be set. If set will override the wait variable. Return true to cancel the wait loop. |
SiteExists(Tenant, String)
Checks if a site collection exists, relies on tenant admin API. Sites that are recycled also return as existing sites
Declaration
public static bool SiteExists(this Tenant tenant, string siteFullUrl)
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
System.String
siteFullUrl
URL to the site collection |
Returns
System.Boolean
True if existing, false if not |
SiteExistsAnywhere(Tenant, String)
Checks if a site collection exists, relies on tenant admin API. Sites that are recycled also return as existing sites, but with a different flag
Declaration
public static SiteExistence SiteExistsAnywhere(this Tenant tenant, string siteFullUrl)
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
System.String
siteFullUrl
URL to the site collection |
Returns
SiteExistence
An enumerated type that can be: No, Yes, Recycled |
SubSiteExists(Tenant, String)
Checks if a sub site exists
Declaration
public static bool SubSiteExists(this Tenant tenant, string siteFullUrl)
Parameters
Tenant
tenant
A tenant object pointing to the context of a Tenant Administration site |
System.String
siteFullUrl
URL to the sub site |
Returns
System.Boolean
True if existing, false if not |
UpdateSiteClassificationsSettings(Tenant, String, IEnumerable<String>, String, String)
Updates Site Classifications settings for the target tenant
Declaration
public static void UpdateSiteClassificationsSettings(this Tenant tenant, string accessToken, IEnumerable<string> classificationsList, string defaultClassification = "", string usageGuidelinesUrl = "")
Parameters
Tenant
tenant
The target tenant |
System.String
accessToken
The OAuth accessToken for Microsoft Graph with Azure AD |
IEnumerable<System.String>
classificationsList
The list of classification values |
System.String
defaultClassification
The default classification |
System.String
usageGuidelinesUrl
The URL of a guidance page |
UpdateSiteClassificationsSettings(Tenant, String, SiteClassificationsSettings)
Updates Site Classifications settings for the target tenant
Declaration
public static void UpdateSiteClassificationsSettings(this Tenant tenant, string accessToken, SiteClassificationsSettings siteClassificationsSettings)
Parameters
Tenant
tenant
The target tenant |
System.String
accessToken
The OAuth accessToken for Microsoft Graph with Azure AD |
SiteClassificationsSettings
siteClassificationsSettings
The site classifications settings to update. |