Class ClientContextExtensions
Class that deals with cloning client context object, getting access token and validates server version
Inheritance
System.Object
ClientContextExtensions
Assembly: PnP.Framework.dll
Syntax
public static class ClientContextExtensions : object
Methods
Checks if an alias is already used for an office 365 group or not
Declaration
public static async Task<bool> AliasExistsAsync(this ClientContext clientContext, string alias)
Parameters
|
ClientContext
clientContext
ClientContext of the site to operate against
|
|
System.String
alias
Alias to verify
|
Returns
|
Task<System.Boolean>
True if in use, false otherwise
|
Clones a ClientContext object while "taking over" the security context of the existing ClientContext instance
Declaration
public static ClientContext Clone(this ClientRuntimeContext clientContext, string siteUrl, Dictionary<string, string> accessTokens = null)
Parameters
|
ClientRuntimeContext
clientContext
ClientContext to be cloned
|
|
System.String
siteUrl
Site URL to be used for cloned ClientContext
|
|
Dictionary<System.String, System.String>
accessTokens
Dictionary of access tokens for sites URLs
|
Returns
|
ClientContext
A ClientContext object created for the passed site URL
|
Clones a ClientContext object while "taking over" the security context of the existing ClientContext instance
Declaration
public static ClientContext Clone(this ClientRuntimeContext clientContext, Uri siteUrl, Dictionary<string, string> accessTokens = null)
Parameters
|
ClientRuntimeContext
clientContext
ClientContext to be cloned
|
|
Uri
siteUrl
Site URL to be used for cloned ClientContext
|
|
Dictionary<System.String, System.String>
accessTokens
Dictionary of access tokens for sites URLs
|
Returns
|
ClientContext
A ClientContext object created for the passed site URL
|
BETA: Creates a Communication Site Collection
Declaration
public static async Task<ClientContext> CreateSiteAsync(this ClientContext clientContext, CommunicationSiteCollectionCreationInformation siteCollectionCreationInformation)
Parameters
Returns
BETA: Creates a Team Site Collection with no group
Declaration
public static async Task<ClientContext> CreateSiteAsync(this ClientContext clientContext, TeamNoGroupSiteCollectionCreationInformation siteCollectionCreationInformation)
Parameters
Returns
BETA: Creates a Team Site Collection
Declaration
public static async Task<ClientContext> CreateSiteAsync(this ClientContext clientContext, TeamSiteCollectionCreationInformation siteCollectionCreationInformation)
Parameters
Returns
Deletes a Communication site or a group-less Modern team site
Declaration
public static async Task<bool> DeleteSiteAsync(this ClientContext clientContext)
Parameters
|
ClientContext
clientContext
|
Returns
Executes the current set of data retrieval queries and method invocations and retries it if needed.
Declaration
public static void ExecuteQueryRetry(this ClientRuntimeContext clientContext, int retryCount = 10, string userAgent = null)
Parameters
|
ClientRuntimeContext
clientContext
clientContext to operate on
|
|
System.Int32
retryCount
Number of times to retry the request
|
|
System.String
userAgent
UserAgent string value to insert for this request. You can define this value in your app's config file using key="SharePointPnPUserAgent" value="PnPRocks">
|
Executes the current set of data retrieval queries and method invocations and retries it if needed using the Task Library.
Declaration
public static Task ExecuteQueryRetryAsync(this ClientRuntimeContext clientContext, int retryCount = 10, string userAgent = null)
Parameters
|
ClientRuntimeContext
clientContext
clientContext to operate on
|
|
System.Int32
retryCount
Number of times to retry the request
|
|
System.String
userAgent
UserAgent string value to insert for this request. You can define this value in your app's config file using key="SharePointPnPUserAgent" value="PnPRocks">
|
Returns
Gets an access token from a instance. Only works when using an add-in or app-only authentication flow.
Declaration
public static string GetAccessToken(this ClientRuntimeContext clientContext)
Parameters
|
ClientRuntimeContext
clientContext
instance to obtain an access token for
|
Returns
|
System.String
Access token for the given instance
|
Declaration
public static async Task<string> GetRequestDigestAsync(this ClientContext context)
Parameters
Returns
Returns the request digest from the current session/site given cookie based auth
Declaration
public static async Task<string> GetRequestDigestAsync(this ClientContext context, CookieContainer cookieContainer)
Parameters
|
ClientContext
context
|
|
CookieContainer
cookieContainer
A cookiecontainer containing FedAuth cookies
|
Returns
Gets a site collection context for the passed web. This site collection client context uses the same credentials
as the passed client context
Declaration
public static ClientContext GetSiteCollectionContext(this ClientRuntimeContext clientContext)
Parameters
|
ClientRuntimeContext
clientContext
Client context to take the credentials from
|
Returns
|
ClientContext
A site collection client context object for the site collection
|
BETA: Groupifies a classic Team Site Collection
Declaration
public static async Task<ClientContext> GroupifySiteAsync(this ClientContext clientContext, TeamSiteCollectionGroupifyInformation siteCollectionGroupifyInformation)
Parameters
|
ClientContext
clientContext
ClientContext instance of the site to be groupified
|
|
TeamSiteCollectionGroupifyInformation
siteCollectionGroupifyInformation
Information needed to groupify this site
|
Returns
|
Task<ClientContext>
The clientcontext of the groupified site
|
Checks the server library version of the context for a minimally required version
Declaration
public static bool HasMinimalServerLibraryVersion(this ClientRuntimeContext clientContext, string minimallyRequiredVersion)
Parameters
|
ClientRuntimeContext
clientContext
clientContext to operate on
|
|
System.String
minimallyRequiredVersion
provide version to validate
|
Returns
|
System.Boolean
True if it has minimal required version, false otherwise
|
Checks the server library version of the context for a minimally required version
Declaration
public static bool HasMinimalServerLibraryVersion(this ClientRuntimeContext clientContext, Version minimallyRequiredVersion)
Parameters
|
ClientRuntimeContext
clientContext
clientContext to operate on
|
|
Version
minimallyRequiredVersion
provide version to validate
|
Returns
|
System.Boolean
True if it has minimal required version, false otherwise
|
Hide the teamify prompt displayed in O365 group connected sites
Declaration
public static async Task<bool> HideTeamifyPromptAsync(this ClientContext clientContext)
Parameters
|
ClientContext
clientContext
ClientContext of the site to operate against
|
Returns
Checks if the used ClientContext is app-only
Declaration
public static bool IsAppOnly(this ClientRuntimeContext clientContext)
Parameters
|
ClientRuntimeContext
clientContext
The ClientContext to inspect
|
Returns
|
System.Boolean
True if app-only, false otherwise
|
Declaration
public static async Task<bool> IsTeamifyPromptHidden(this ClientContext clientContext)
Parameters
|
ClientContext
clientContext
|
Returns
Checks whether the teamify prompt is hidden in O365 Group connected sites
Declaration
public static async Task<bool> IsTeamifyPromptHiddenAsync(this ClientContext clientContext)
Parameters
|
ClientContext
clientContext
ClientContext of the site to operate against
|
Returns
Returns the number of pending requests
Declaration
public static int PendingRequestCount(this ClientRuntimeContext clientContext)
Parameters
|
ClientRuntimeContext
clientContext
Client context to check the pending requests for
|
Returns
|
System.Int32
The number of pending requests
|
Enable MS Teams team on a group connected team site
Declaration
public static async Task<string> TeamifyAsync(this ClientContext clientContext, string graphAccessToken = null)
Parameters
|
ClientContext
clientContext
|
|
System.String
graphAccessToken
|
Returns