0

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

1 Answer 1

3

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)!

2
  • so in my case the spCurrentSite variable inside SPWeb spCurrentSite = properties.OpenWeb(); will be a reference to the current site (either the root site or a sub-site) where the event receiver have executed.. is this correct? and to get a reference to the site collection i can do SPSite spCurrentSiteCollection = spCurrentSite.Site; ??
    – john Gu
    Jan 30, 2017 at 1:16
  • 1
    That's correct!
    – Evariste
    Jan 30, 2017 at 6:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.