Skip to content

Extension methods

takerusilt edited this page Aug 1, 2016 · 1 revision

Elevated privileges

Gets the securable objects in elevated privileges. The elevated SPSite object is disposed after execution.

void WithElevatedPrivileges(this SPSite, Action<SPSite>);
void WithElevatedPrivileges(this SPWeb, Action<SPWeb>);
void WithElevatedPrivileges(this SPList, Action<SPList>);
void WithElevatedPrivileges(this SPListItem, Action<SPListItem>);

Unsafe updates

Turns on unsafe update flag to allow updates in GET requests. The flag is restored upon disposing.

IDisposable GetAllowUnsafeUpdatesScope(this SPSite);
IDisposable GetAllowUnsafeUpdatesScope(this SPWeb);

Role definitions and permissions

Shorthand methods to create custom role definitions, grant and remove permissions of a securable object to a SharePoint member.

SPRoleDefinition EnsureCustomRoleDefinition(this SPSite, string, SPBasePermissions);
SPRoleDefinition EnsureCustomRoleDefinition(this SPSite, string, SPRoleType, SPBasePermissions);
void GrantPermission(this SPSecurableObject, SPPrincipal, SPRoleDefinition);
void GrantPermission(this SPSecurableObject, SPPrincipal, SPRoleDefinition, bool);
void RemovePermission(this SPSecurableObject, SPPrincipal, SPRoleDefinition);
SPBasePermissions GetEffectivePermissions(this SPRoleAssignment);

File check-outs and approvals

Ensures the list item, file, or folder to be approved or published.

void EnsureApproved(this SPListItem);
void EnsureApproved(this SPFolder);
void EnsurePublished(this SPFile, string);
IDisposable GetCheckOutScope(this SPFile, bool);
void EnableScheduledPublishing(this SPList);

Add-or-update operation

Shorthand methods for common add-or-update operations.

SPList EnsureListByUrl(this SPWeb, string, string, SPListTemplateType);
SPFolder EnsureSubFolder(this SPFolder, string);
SPEventReceiverDefinition EnsureEventReceiver(this SPEventReceiverDefinitionCollection, SPEventReceiverType, Type, SPEventReceiverSynchronization);
SPGroup EnsureGroup(this SPWeb, string);
SPWorkflowAssociation EnsureWorkflowAssociation(this SPList, Guid)SPWorkflowAssociation EnsureWorkflowAssociation(this SPContentType, Guid);

Gets or sets the root term set or term the taxonomy field is associated to.

TermSetItem GetTermAnchor(this TaxonomyField, TaxonomySession);
void SetTermAnchor(this TaxonomyField, TermSetItem);

Create the term set of specified GUID if it does not exists in the term store.

TermSet EnsureTermSet(this TermStore, Guid, string, string);

Create the term under the term set if it does not exists. Optionally identified by custom property.

Term EnsureTerm(this TermSet, string);
Term EnsureTermWithCustomProperty(this TermSet, string, string, string)