Uncategorized

Information about WebAdding & Webprovisioned events

In SharePoint 2010, there are number of new events that you can override. One of them is WebAdding, interesting enough this event allows you to cancel the Web (of type SPWeb, confused with SharePoint terminology? see table at the end of the post) creation process. This is actually  quite powerful, because you can perform validation based on complex business rules, and if required can even cancel the web creation process. But keep in mind that SharePoint 2010 provides two events related to web creation process, as discussed below.

  • ·         Web is being created, and this process fire up WebAdding. You can cancel the event and as a result web will not be created.
  • ·         Web is created. This is after SharePoint is done with provisioning all the required files for the Web. This can be captured by WeProvisioned event. However as web is already created, you cannot cancel the creation process.

When SharePoint is creating a web, you will not able to access all the items (e.g page themselves), so tasks like populating pages with content cannot be done inside the WebAdding event. For performing these tasks override WebProvisioned event. The reason why it’s important to understand this is because WebAdding event is basically fire on parent web, not the web which is being created.  

See the image below.

image

So when you create the SubWeb1 the WebAdding will be fire on RootWeb .This raises a question will WebAdding event will fire when RootWeb is being created?

The answer is No, it will not fire because there is no parent web for it. In fact if you check for ParentWeb property on the RootWeb , it will always return null. Make sure if you are overriding WebAdding event, you carter for this case, this will help avoiding exceptions.

Term

Referring to

Web

Sub web of type SPWeb. Each Site collection can have one or more sub web. There is special web called RootWeb this refers to top level web which act as a parent and cannot be deleted. Sometimes terms Sub sites or just Web is used instead of sub web.

Site

Site collection of type SPSite, this is what contains the sub web (SPWeb). The word Site is mostly used while referring to site collection.

Web App

Web application of type SPWebApplication. Web application can contain multiple site collections.

Advertisements

3 thoughts on “Information about WebAdding & Webprovisioned events

  1. What about Webprovisioned event? Will it fire after a root web has been created?
    How do you attach it to the web application so each site collection created, will fire the event after the root web was created?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s