Table of Contents

Class PnPContext

Namespace
PnP.Core.Services
Assembly
PnP.Core.dll

PnP Context class...the glue between the model and the data stores

public class PnPContext : IPnPContext, IDisposable
Inheritance
PnPContext
Implements
Inherited Members
Extension Methods

Properties

AuthenticationProvider

Connected authentication provider

public IAuthenticationProvider AuthenticationProvider { get; }

Property Value

IAuthenticationProvider

AzureADLoginAuthority

Returns the Azure AD Login authority (e.g. login.microsoftonline.com) to use when Environment is set to Custom

public string AzureADLoginAuthority { get; }

Property Value

string

ContentTypeHub

Entry point for the ContentTypeHub object

public IContentTypeHub ContentTypeHub { get; }

Property Value

IContentTypeHub

CurrentBatch

Current batch, used for implicit batching

public Batch CurrentBatch { get; }

Property Value

Batch

Environment

Returns the used Microsoft 365 cloud environment

public Microsoft365Environment? Environment { get; }

Property Value

Microsoft365Environment?

GraphAlwaysUseBeta

If true than all requests to Microsoft Graph use the beta endpoint

public bool GraphAlwaysUseBeta { get; set; }

Property Value

bool

GraphCanUseBeta

If true than the Graph beta endpoint is used when there's no other option, default approach stays using the v1 endpoint

public bool GraphCanUseBeta { get; set; }

Property Value

bool

GraphClient

Connected Microsoft Graph client

public MicrosoftGraphClient GraphClient { get; }

Property Value

MicrosoftGraphClient

GraphFirst

Controls whether the library will try to use Microsoft Graph over REST whenever that's defined in the model

public bool GraphFirst { get; set; }

Property Value

bool

Group

Entry point for the Microsoft 365 Group Object

public IGraphGroup Group { get; }

Property Value

IGraphGroup

HasPendingRequests

Are there pending requests to execute (in the case of batching)

public bool HasPendingRequests { get; }

Property Value

bool

Logger

Connected logger

public ILogger Logger { get; }

Property Value

ILogger

Me

Entry point for the Me object

public IMe Me { get; }

Property Value

IMe

MicrosoftGraphAuthority

Returns the Microsoft Graph authority (e.g. graph.microsoft.com) to use when Environment is set to Custom

public string MicrosoftGraphAuthority { get; }

Property Value

string

Properties

Collection for custom properties that you want to attach to a PnPContext

public IDictionary<string, object> Properties { get; }

Property Value

IDictionary<string, object>

RestClient

Connected SharePoint REST client

public SharePointRestClient RestClient { get; }

Property Value

SharePointRestClient

Site

Entry point for the Site Object

public ISite Site { get; }

Property Value

ISite

Social

Entry point for the social-related APIs

public ISocial Social { get; }

Property Value

ISocial

Team

Entry point for the Team Object

public ITeam Team { get; }

Property Value

ITeam

TermStore

Entry point for the Microsoft 365 TermStore

public ITermStore TermStore { get; }

Property Value

ITermStore

Uri

Uri of the SharePoint site we're working against

public Uri Uri { get; }

Property Value

Uri

Web

Entry point for the Web Object

public IWeb Web { get; }

Property Value

IWeb

Methods

Clone()

Clones this context into a new context for the same SharePoint site

public PnPContext Clone()

Returns

PnPContext

New PnPContext

Clone(Guid)

Clones this context for another SharePoint site

public PnPContext Clone(Guid groupId)

Parameters

groupId Guid

Id of the other Microsoft 365 group to create a PnPContext for

Returns

PnPContext

New PnPContext

Clone(string)

Clones this context for another SharePoint site provided as configuration

public PnPContext Clone(string name)

Parameters

name string

The name of the SPOContext configuration to use

Returns

PnPContext

New PnPContext for the request config

Clone(Uri)

Clones this context for another SharePoint site

public PnPContext Clone(Uri uri)

Parameters

uri Uri

Uri of the other SharePoint site

Returns

PnPContext

New PnPContext

CloneAsync()

Clones this context into a new context for the same SharePoint site

public Task<PnPContext> CloneAsync()

Returns

Task<PnPContext>

New PnPContext

CloneAsync(Guid)

Clones this context for another SharePoint site

public Task<PnPContext> CloneAsync(Guid groupId)

Parameters

groupId Guid

Id of the other Microsoft 365 group to create a PnPContext for

Returns

Task<PnPContext>

New PnPContext

CloneAsync(string)

Clones this context for another SharePoint site provided as configuration

public Task<PnPContext> CloneAsync(string name)

Parameters

name string

The name of the SPOContext configuration to use

Returns

Task<PnPContext>

New PnPContext for the request config

CloneAsync(Uri)

Clones this context for another SharePoint site

public Task<PnPContext> CloneAsync(Uri uri)

Parameters

uri Uri

Uri of the other SharePoint site

Returns

Task<PnPContext>

New PnPContext

Dispose()

Disposes this PnPContext

public void Dispose()

Dispose(bool)

Disposes this PnPContext

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

Do we need to dispose resources

Execute(Batch, bool)

Method to execute a given batch

public List<BatchResult> Execute(Batch batch, bool throwOnError = true)

Parameters

batch Batch

Batch to execute

throwOnError bool

Throw an exception on the first encountered error in the batch

Returns

List<BatchResult>

The asynchronous task that will be executed

Execute(bool)

Method to execute the current batch

public List<BatchResult> Execute(bool throwOnError = true)

Parameters

throwOnError bool

Throw an exception on the first encountered error in the batch

Returns

List<BatchResult>

The asynchronous task that will be executed

ExecuteAsync(Batch, bool)

Method to execute a given batch

public Task<List<BatchResult>> ExecuteAsync(Batch batch, bool throwOnError = true)

Parameters

batch Batch

Batch to execute

throwOnError bool

Throw an exception on the first encountered error in the batch

Returns

Task<List<BatchResult>>

The asynchronous task that will be executed

ExecuteAsync(bool)

Method to execute the current batch

public Task<List<BatchResult>> ExecuteAsync(bool throwOnError = true)

Parameters

throwOnError bool

Throw an exception on the first encountered error in the batch

Returns

Task<List<BatchResult>>

The asynchronous task that will be executed

GetLongRunningOperation(string)

Gets an ongoing Graph long-running operation.

public ILongRunningOperation GetLongRunningOperation(string location)

Parameters

location string

The location of the operation

Returns

ILongRunningOperation

An ILongRunningOperation associated with the location

NewBatch()

Creates a new batch

public Batch NewBatch()

Returns

Batch