Class WebExtensions
Class that deals with site (both site collection and web site) creation, status, retrieval and settings
Inheritance
Namespace: Microsoft.SharePoint.Client
Assembly: PnP.Framework.dll
Syntax
public static class WebExtensions : object
Methods
AddIndexedPropertyBagKey(Web, String)
Marks a property bag key for indexing
Declaration
public static bool AddIndexedPropertyBagKey(this Web web, string key)
Parameters
Web
web
The web to process |
System. The key to mark for indexing |
Returns
System. Returns True if succeeded |
AddRemoteEventReceiver(Web, String, String, EventReceiverType, EventReceiverSynchronization, Boolean)
Registers a remote event receiver
Declaration
public static EventReceiverDefinition AddRemoteEventReceiver(this Web web, string name, string url, EventReceiverType eventReceiverType, EventReceiverSynchronization synchronization, bool force)
Parameters
Web
web
The web to process |
System. The name of the event receiver (needs to be unique among the event receivers registered on this list) |
System. The URL of the remote WCF service that handles the event |
Event
|
Event
|
System. If True any event already registered with the same name will be removed first. |
Returns
Event Returns an EventReceiverDefinition if succeeded. Returns null if failed. |
AddRemoteEventReceiver(Web, String, String, EventReceiverType, EventReceiverSynchronization, Int32, Boolean)
Registers a remote event receiver
Declaration
public static EventReceiverDefinition AddRemoteEventReceiver(this Web web, string name, string url, EventReceiverType eventReceiverType, EventReceiverSynchronization synchronization, int sequenceNumber, bool force)
Parameters
Web
web
The web to process |
System. The name of the event receiver (needs to be unique among the event receivers registered on this list) |
System. The URL of the remote WCF service that handles the event |
Event The type of event for the event receiver. |
Event An enumeration that specifies the synchronization state for the event receiver. |
System. An integer that represents the relative sequence of the event. |
System. If True any event already registered with the same name will be removed first. |
Returns
Event Returns an EventReceiverDefinition if succeeded. Returns null if failed. |
ApplyProvisioningTemplate(Web, ProvisioningTemplate, ProvisioningTemplateApplyingInformation)
Can be used to apply custom remote provisioning template on top of existing site.
Declaration
public static void ApplyProvisioningTemplate(this Web web, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation applyingInformation = null)
Parameters
Web
web
web to apply remote template |
Provisioning ProvisioningTemplate with the settings to be applied |
Provisioning Specified additional settings and or properties |
ClaimsHaveRoleAssignment(Web, String, String)
Checks if the passed claims are assigned a role
Declaration
public static bool ClaimsHaveRoleAssignment(this Web web, string claim1, string claim2)
Parameters
Web
web
Web to check |
System. Claim to check |
System. Claim to check |
Returns
System. True if claim1 or claim2 has a role |
CreateWeb(Web, SiteEntity, Boolean, Boolean)
Adds a new child Web (site) to a parent Web.
Declaration
public static Web CreateWeb(this Web parentWeb, SiteEntity subsite, bool inheritPermissions = true, bool inheritNavigation = true)
Parameters
Web
parentWeb
The parent Web (site) to create under |
Site Details of the Web (site) to add. Only Title, Url (as the leaf URL), Description, Template and Language are used. |
System. Specifies whether the new site will inherit permissions from its parent site. |
System. Specifies whether the site inherits navigation. |
Returns
Web
|
CreateWeb(Web, String, String, String, String, Int32, Boolean, Boolean)
Adds a new child Web (site) to a parent Web.
Declaration
public static Web CreateWeb(this Web parentWeb, string title, string leafUrl, string description, string template, int language, bool inheritPermissions = true, bool inheritNavigation = true)
Parameters
Web
parentWeb
The parent Web (site) to create under |
System. The title of the new site. |
System. A string that represents the URL leaf name. |
System. The description of the new site. |
System. The name of the site template to be used for creating the new site. |
System. The locale ID that specifies the language of the new site. |
System. Specifies whether the new site will inherit permissions from its parent site. |
System. Specifies whether the site inherits navigation. |
Returns
Web
|
DeleteWeb(Web, String)
Deletes the child website with the specified leaf URL, from a parent Web, if it exists.
Declaration
public static bool DeleteWeb(this Web parentWeb, string leafUrl)
Parameters
Web
parentWeb
The parent Web (site) to delete from |
System. A string that represents the URL leaf name. |
Returns
System. true if the web was deleted; otherwise false if nothing was done |
DeployApplicationPackageToAppCatalog(Web, String, String, Boolean, Boolean)
Adds a package to the tenants app catalog and by default deploys it if the package is a client side package (sppkg)
Declaration
public static ListItem DeployApplicationPackageToAppCatalog(this Web web, string spPkgName, string spPkgPath, bool autoDeploy = true, bool overwrite = true)
Parameters
Web
web
Web to operate against |
System. Name of the package to upload (e.g. demo.sppkg) |
System. Path on the filesystem where this package is stored |
System. Automatically deploy the package, only applies to client side packages (sppkg) |
System. Overwrite the package if it was already listed in the app catalog |
Returns
List The ListItem of the added package row |
DeployApplicationPackageToAppCatalog(Web, String, String, Boolean, Boolean, Boolean)
Adds a package to the tenants app catalog and by default deploys it if the package is a client side package (sppkg)
Declaration
public static ListItem DeployApplicationPackageToAppCatalog(this Web web, string spPkgName, string spPkgPath, bool autoDeploy = true, bool skipFeatureDeployment = true, bool overwrite = true)
Parameters
Web
web
Tenant to operate against |
System. Name of the package to upload (e.g. demo.sppkg) |
System. Path on the filesystem where this package is stored |
System. Automatically deploy the package, only applies to client side packages (sppkg) |
System. Skip the feature deployment step, allows for a one-time central deployment of your solution |
System. Overwrite the package if it was already listed in the app catalog |
Returns
List The ListItem of the added package row |
DisableRequestAccess(Web)
Disables the request access on the web.
Declaration
public static void DisableRequestAccess(this Web web)
Parameters
Web
web
The web to disable request access. |
EnableRequestAccess(Web)
Enables request access for the default owners group of the site.
Declaration
public static void EnableRequestAccess(this Web web)
Parameters
Web
web
The web to enable request access. |
EnableRequestAccess(Web, IEnumerable<String>)
Enables request access for the specified e-mail addresses.
Declaration
public static void EnableRequestAccess(this Web web, IEnumerable<string> emails)
Parameters
Web
web
The web to enable request access. |
IEnumerable<System. The e-mail addresses to send access requests to. |
EnableRequestAccess(Web, String)
Enables request access for the specified e-mail address.
Declaration
public static void EnableRequestAccess(this Web web, string email)
Parameters
Web
web
The web to enable request access. |
System. The e-mail address to send access requests to. |
EnableRequestAccess(Web, String[])
Enables request access for the specified e-mail addresses.
Declaration
public static void EnableRequestAccess(this Web web, params string[] emails)
Parameters
Web
web
The web to enable request access. |
System. The e-mail addresses to send access requests to. |
GetAdmins(Web)
Returns the admins of this site
Declaration
public static List<UserEntity> GetAdmins(this Web web)
Parameters
Web
web
Site to scan |
Returns
List<User List of admins |
GetAllWebUrls(Site)
Gets the collection of the URLs of all Web sites that are contained within the site collection, including the top-level site and its subsites.
Declaration
public static IEnumerable<string> GetAllWebUrls(this Site site)
Parameters
Site
site
Site collection to retrieve the URLs for. |
Returns
IEnumerable<System. An enumeration containing the full URLs as strings. |
Remarks
This is analagous to the
SPSite.AllWebs
property and can be used to get a collection
of all web site URLs to loop through, e.g. for branding.
GetAppCatalog(Web)
Gets the Uri for the tenant's app catalog site (if that one has already been created)
Declaration
public static Uri GetAppCatalog(this Web web)
Parameters
Web
web
Web to operate against |
Returns
Uri
The Uri holding the app catalog site URL |
GetAppInstances(Web, Expression<Func<AppInstance, Object>>[])
Returns all app instances
Declaration
public static ClientObjectList<AppInstance> GetAppInstances(this Web web, params Expression<Func<AppInstance, object>>[] expressions)
Parameters
Web
web
The site to process |
Expression<Func<App List of lambda expressions of properties to load when retrieving the object |
Returns
Client all app instances |
GetBaseTemplateId(Web)
Returns the Base Template ID for the current web
Declaration
public static string GetBaseTemplateId(this Web parentWeb)
Parameters
Web
parentWeb
The parent Web (site) to get the base template from |
Returns
System. The Base Template ID for the current web |
GetBlogsFromList(Web, String, String, String)
Returns the blogs from a web, optionally filtered on blog name
Declaration
public static ListItemCollection GetBlogsFromList(this Web web, string webRelativeListName, string pageNameStartsWith = null, string folder = null)
Parameters
Web
web
Web to get the blogs from |
System. Web relative URL of the blog list (e.g. Posts) |
System. Filter to get all blogs starting with |
System. Folder to search in |
Returns
List A list of pages (ListItem instances) |
GetEventReceiverById(Web, Guid)
Returns an event receiver definition
Declaration
public static EventReceiverDefinition GetEventReceiverById(this Web web, Guid id)
Parameters
Web
web
Web to process |
Guid
id
The id of event receiver |
Returns
Event Returns an EventReceiverDefinition if succeeded. Returns null if failed. |
GetEventReceiverByName(Web, String)
Returns an event receiver definition
Declaration
public static EventReceiverDefinition GetEventReceiverByName(this Web web, string name)
Parameters
Web
web
Web to process |
System. The name of the receiver |
Returns
Event Returns an EventReceiverDefinition if succeeded. Returns null if failed. |
GetEveryoneExceptExternalUsersClaim(Web)
Resolves the Everyone Except External Users claim
Declaration
public static string GetEveryoneExceptExternalUsersClaim(this Web web)
Parameters
Web
web
web to use for the resolving |
Returns
System. Loginname for the "Everyone Except External Users" claim |
GetIndexedPropertyBagKeys(Web)
Returns all keys in the property bag that have been marked for indexing
Declaration
public static IEnumerable<string> GetIndexedPropertyBagKeys(this Web web)
Parameters
Web
web
The site to process |
Returns
IEnumerable<System. all indexed property bag keys |
GetListByName(Web, String)
Gets list from web in an SP2010 compatible fashion
Declaration
public static List GetListByName(this Web web, string listName)
Parameters
Web
web
Web to operate on |
System. List to lookup |
Returns
List
List instance |
GetMembers(Web)
Returns members of this site
Declaration
public static List<UserEntity> GetMembers(this Web web)
Parameters
Web
web
Web to scan |
Returns
List<User Members of this web |
GetName(Web)
Gets the name part of the URL of the Server Relative URL of the Web.
Declaration
public static string GetName(this Web web)
Parameters
Web
web
The Web to process |
Returns
System. A string that contains the name part of the Server Relative URL (the last part of the URL) of a web. |
GetOwners(Web)
Returns owners of this web
Declaration
public static List<UserEntity> GetOwners(this Web web)
Parameters
Web
web
Web to scan |
Returns
List<User List of owners |
GetPages(Web, String, String)
Returns the site pages from a web, optionally filtered on pagename
Declaration
public static ListItemCollection GetPages(this Web web, string pageNameStartsWith = null, string folder = null)
Parameters
Web
web
Web to get the pages from |
System. Filter to get all pages starting with |
System.
|
Returns
List A list of pages (ListItem instances) |
GetPagesFromList(Web, String, String, String)
Returns the site pages from a web, optionally filtered on pagename
Declaration
public static ListItemCollection GetPagesFromList(this Web web, string webRelativeListName, string pageNameStartsWith = null, string folder = null)
Parameters
Web
web
Web to get the pages from |
System. Web relative URL of the list (e.g. SiteAssets) |
System. Filter to get all pages starting with |
System. Folder to search in |
Returns
List A list of pages (ListItem instances) |
GetPagesLibraryId(Web)
Get Pages Library ID for the Web
Declaration
public static string GetPagesLibraryId(this Web web)
Parameters
Web
web
Web to operate on |
Returns
System. ID of the pages library |
GetPostsLibrary(Web)
Gets blog post library in an SP2010 compatible fashion
Declaration
public static List GetPostsLibrary(this Web web)
Parameters
Web
web
Web to operate on |
Returns
List
Blog post library |
GetPropertyBagValueDateTime(Web, String, DateTime)
Get DateTime typed property bag value. If does not contain, returns default value.
Declaration
public static DateTime? GetPropertyBagValueDateTime(this Web web, string key, DateTime defaultValue)
Parameters
Web
web
Web to read the property bag value from |
System. Key of the property bag entry to return |
Date
|
Returns
System. Value of the property bag entry as integer |
GetPropertyBagValueInt(Web, String, Int32)
Get int typed property bag value. If does not contain, returns default value.
Declaration
public static int? GetPropertyBagValueInt(this Web web, string key, int defaultValue)
Parameters
Web
web
Web to read the property bag value from |
System. Key of the property bag entry to return |
System.
|
Returns
System. Value of the property bag entry as integer |
GetPropertyBagValueString(Web, String, String)
Get string typed property bag value. If does not contain, returns given default value.
Declaration
public static string GetPropertyBagValueString(this Web web, string key, string defaultValue)
Parameters
Web
web
Web to read the property bag value from |
System. Key of the property bag entry to return |
System.
|
Returns
System. Value of the property bag entry as string |
GetProvisioningTemplate(Web)
Can be used to extract custom provisioning template from existing site. The extracted template will be compared with the default base template.
Declaration
public static ProvisioningTemplate GetProvisioningTemplate(this Web web)
Parameters
Web
web
Web to get template from |
Returns
Provisioning ProvisioningTemplate object with generated values from existing site |
GetProvisioningTemplate(Web, ProvisioningTemplateCreationInformation)
Can be used to extract custom provisioning template from existing site. The extracted template will be compared with the default base template.
Declaration
public static ProvisioningTemplate GetProvisioningTemplate(this Web web, ProvisioningTemplateCreationInformation creationInfo)
Parameters
Web
web
Web to get template from |
Provisioning Specifies additional settings and/or properties |
Returns
Provisioning ProvisioningTemplate object with generated values from existing site |
GetRequestAccessEmails(Web)
Gets the request access e-mail addresses of the web.
Declaration
public static IEnumerable<string> GetRequestAccessEmails(this Web web)
Parameters
Web
web
The web to get the request access e-mail addresses from. |
Returns
IEnumerable<System. The request access e-mail addresses of the web. |
GetSitePagesLibrary(Web)
Gets site pages library from web
Declaration
public static List GetSitePagesLibrary(this Web web)
Parameters
Web
web
Web to operate on |
Returns
List
Site pages library instance |
GetUrl(Web)
Method to bypass missing property in SharePoint 2010
Declaration
public static string GetUrl(this Web web)
Parameters
Web
web
Web to operate on |
Returns
System. web url |
Remarks
Only required on source contexts
GetVisitors(Web)
Returns visitors of this site
Declaration
public static List<UserEntity> GetVisitors(this Web web)
Parameters
Web
web
Web to scan |
Returns
List<User Visitors of this web |
GetWeb(Web, String)
Returns the child Web site with the specified leaf URL.
Declaration
public static Web GetWeb(this Web parentWeb, string leafUrl)
Parameters
Web
parentWeb
The Web site to check under |
System. A string that represents the URL leaf name. |
Returns
Web
The requested Web, if it exists, otherwise null. |
Remarks
The ServerRelativeUrl property of the retrieved Web is instantiated.
InstallSolution(Site, Guid, String, Int32, Int32)
Uploads and installs a sandbox solution package (.WSP) file, replacing existing solution if necessary.
Declaration
public static void InstallSolution(this Site site, Guid packageGuid, string sourceFilePath, int majorVersion = 1, int minorVersion = 0)
Parameters
Site
site
Site collection to install to |
Guid
packageGuid
ID of the solution, from the solution manifest (required for the remove step) |
System. Path to the sandbox solution package (.WSP) file |
System. Optional major version of the solution, defaults to 1 |
System. Optional minor version of the solution, defaults to 0 |
IsAdminSite(Web)
Checks if the site is the SharePoint Admin site
Declaration
public static bool IsAdminSite(this Web web)
Parameters
Web
web
|
Returns
System.
|
IsNoScriptSite(Site)
Performs a best effort detection of if the site in question has no script enabled or not. Detection is done by verifying if the authenticated user has AddAndCustomizePages permission on the web. Detection will return a false positive if the current user does not have the AddAndCustomizePages permission.
See https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f for the effects of NoScript
Declaration
public static bool IsNoScriptSite(this Site site)
Parameters
Site
site
site to verify |
Returns
System. True if noscript, false otherwise |
IsNoScriptSite(Web)
Performs a best effort detection of if the site in question has no script enabled or not. Detection is done by verifying if the authenticated user has AddAndCustomizePages permission on the web. Detection will return a false positive if the current user does not have the AddAndCustomizePages permission.
See https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f for the effects of NoScript
Declaration
public static bool IsNoScriptSite(this Web web)
Parameters
Web
web
Web to verify |
Returns
System. True if noscript, false otherwise |
IsPublishingWeb(Web)
Checks if the current web is a publishing site or not
Declaration
public static bool IsPublishingWeb(this Web web)
Parameters
Web
web
Web to check |
Returns
System. True is publishing site, false otherwise |
IsSubSite(Web)
Checks if the current web is a sub site or not
Declaration
public static bool IsSubSite(this Web web)
Parameters
Web
web
Web to check |
Returns
System. True is sub site, false otherwise |
MySiteSearch(Web)
Returns all my site site collections
Declaration
public static List<SiteEntity> MySiteSearch(this Web web)
Parameters
Web
web
Site to be processed - can be root web or sub site |
Returns
List<Site All my site site collections |
PropertyBagContainsKey(Web, String)
Checks if the given property bag entry exists
Declaration
public static bool PropertyBagContainsKey(this Web web, string key)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System. Key of the property bag entry to check |
Returns
System. True if the entry exists, false otherwise |
ReIndexWeb(Web)
Queues a web for a full crawl the next incremental/continous crawl
Declaration
public static void ReIndexWeb(this Web web)
Parameters
Web
web
Site to be processed |
RemoveAppInstanceByTitle(Web, String)
Removes the app instance with the specified title.
Declaration
public static bool RemoveAppInstanceByTitle(this Web web, string appTitle)
Parameters
Web
web
Web to remove the app instance from |
System. Title of the app instance to remove |
Returns
System. true if the the app instance was removed; false if it does not exist |
RemoveIndexedPropertyBagKey(Web, String)
Unmarks a property bag key for indexing
Declaration
public static bool RemoveIndexedPropertyBagKey(this Web web, string key)
Parameters
Web
web
The site to process |
System. The key to unmark for indexed. Case-sensitive |
Returns
System. Returns True if succeeded |
RemovePropertyBagValue(Web, String)
Removes a property bag value from the property bag
Declaration
public static void RemovePropertyBagValue(this Web web, string key)
Parameters
Web
web
The site to process |
System. The key to remove |
SetLocalizationLabels(Web, String, String, String)
Can be used to set translations for different cultures.
Declaration
public static void SetLocalizationLabels(this Web web, string cultureName, string titleResource, string descriptionResource)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System. Culture name like en-us or fi-fi |
System. Localized Title string |
System. Localized Description string |
Examples
web.SetLocalizationForSiteLabels("fi-fi", "Name of the site in Finnish", "Description in Finnish");
SetPageOutputCache(Web, Boolean, Int32, Int32, Boolean)
Sets output cache on publishing web. The settings can be maintained from UI by visiting URL /_layouts/15/sitecachesettings.aspx
Declaration
public static void SetPageOutputCache(this Web web, bool enableOutputCache, int anonymousCacheProfileId, int authenticatedCacheProfileId, bool debugCacheInformation)
Parameters
Web
web
SharePoint web |
System. Specify true to enable output cache. False otherwise. |
System. Applies for anonymous users access for a site in Site Collection. Id of the profile specified in "Cache Profiles" list. |
System. Applies for authenticated users access for a site in the Site Collection. Id of the profile specified in "Cache Profiles" list. |
System. Specify true to enable the display of additional cache information on pages in this site collection. False otherwise. |
SetPropertyBagValue(Web, String, DateTime)
Sets a key/value pair in the web property bag
Declaration
public static void SetPropertyBagValue(this Web web, string key, DateTime value)
Parameters
Web
web
Web that will hold the property bag entry |
System. Key for the property bag entry |
Date Datetime value for the property bag entry |
SetPropertyBagValue(Web, String, Int32)
Sets a key/value pair in the web property bag
Declaration
public static void SetPropertyBagValue(this Web web, string key, int value)
Parameters
Web
web
Web that will hold the property bag entry |
System. Key for the property bag entry |
System. Integer value for the property bag entry |
SetPropertyBagValue(Web, String, String)
Sets a key/value pair in the web property bag
Declaration
public static void SetPropertyBagValue(this Web web, string key, string value)
Parameters
Web
web
Web that will hold the property bag entry |
System. Key for the property bag entry |
System. String value for the property bag entry |
SiteSearch(Web)
Returns all site collections that are indexed. In MT the search center, mysite host and contenttype hub are defined as non indexable by default and thus are not returned
Declaration
public static List<SiteEntity> SiteSearch(this Web web)
Parameters
Web
web
Site to be processed - can be root web or sub site |
Returns
List<Site All site collections |
SiteSearch(Web, String, Boolean, Nullable<Guid>)
Returns the site collections that comply with the passed keyword query
Declaration
public static List<SiteEntity> SiteSearch(this Web web, string keywordQueryValue, bool trimDuplicates = false, Guid? sourceResultId = null)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System. Keyword query |
System. Indicates if duplicates should be trimmed or not |
System. Indicated which search results source to use |
Returns
List<Site All found site collections |
SiteSearchScopedByTitle(Web, String)
Returns all site collection that match with the provided title
Declaration
public static List<SiteEntity> SiteSearchScopedByTitle(this Web web, string siteTitle)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System. Title of the site to search for |
Returns
List<Site All found site collections |
SiteSearchScopedByUrl(Web, String)
Returns all site collection that start with the provided URL
Declaration
public static List<SiteEntity> SiteSearchScopedByUrl(this Web web, string siteUrl)
Parameters
Web
web
Site to be processed - can be root web or sub site |
System. Base URL for which sites can be returned |
Returns
List<Site All found site collections |
UninstallSolution(Site, Guid, String, Int32, Int32)
Uninstalls a sandbox solution package (.WSP) file
Declaration
public static void UninstallSolution(this Site site, Guid packageGuid, string fileName, int majorVersion = 1, int minorVersion = 0)
Parameters
Site
site
Site collection to install to |
Guid
packageGuid
ID of the solution, from the solution manifest |
System. filename of the WSP file to uninstall |
System. Optional major version of the solution, defaults to 1 |
System. Optional minor version of the solution, defaults to 0 |
WebExists(Web, String)
Determines if a child Web site with the specified leaf URL exists.
Declaration
public static bool WebExists(this Web parentWeb, string leafUrl)
Parameters
Web
parentWeb
The Web site to check under |
System. A string that represents the URL leaf name. |
Returns
System. true if the Web (site) exists; otherwise false |
WebExistsByTitle(Web, String)
Determines if a web exists by title.
Declaration
public static bool WebExistsByTitle(this Web parentWeb, string title)
Parameters
Web
parentWeb
Parent web to check under. |
System. Title of the web to check. |
Returns
System. True if a web with the given title exists. |
WebExistsFullUrl(ClientRuntimeContext, String)
Determines if a Web (site) exists at the specified full URL, either accessible or that returns an access error.
Declaration
public static bool WebExistsFullUrl(this ClientRuntimeContext context, string webFullUrl)
Parameters
Client Existing context, used to provide credentials. |
System. Full URL of the site to check. |
Returns
System. true if the Web (site) exists; otherwise false |