Question

I have the following event receiver which will get fired when a custom list item is created, and the event receiver is scoped at the site level.:-

 public override void ItemAdded(SPItemEventProperties properties)
        {
            base.ItemAdded(properties);

               SPWeb spCurrentSite = properties.OpenWeb();

now when i hover my mouse over the SPWeb spCurrentSite = properties.OpenWeb(); line of code , i got this missleading documentation:-

enter image description here

so it mentioned that the OpenWeb() will return an object of type SPWeb but at the same time the documentation is saying "Returns the site in which the event occurred"!! so should the documentation be "Returns the web in which the event occurred" by replacing site with web !! as the OpenWeb() will return the current web (could be a sub-site) and not the current site collection .. is this correct ?

thanks

Was it helpful?

Solution

The SharePoint terminology is vert confusing.

Officially, you have the "site collections", and each site collection contains "site"s (the root site and all its sub-sites are sites). There's no "web".
That's for the admin/user point of view.
However, from the developer point of view, things are a little different: a site collection is an SPSite while a site is an SPWeb.
So there's always a confusion, and sometimes there's even mistakes in the official documentation where a collection is called a... "site" from time to time! In theses cases, only the context can help understanding.

Anyway, in your example, the IntelliSense tooltip is correct: OpenWeb returns a site (i.e. the root site or a sub-site)!

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top