SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does properties.OpenWeb() create a new SPRequest object or does it refer to the existing SPWeb object already there in the properties object? Should we manually dispose of the SPWeb obtained in this manner?

Is the second line safer?

        SPWeb _web = properties.OpenWeb();
        SPWeb _web = properties.ListItem.ParentList.ParentWeb;
share|improve this question
By the way, current SPDisposeCheck fails to detect this undisposed SPWeb scenario. – Alexey Krasheninnikov Jan 25 '10 at 9:23
up vote 12 down vote accepted

In SharePoint 2007 you need to dispose the returned SPWeb if you use properties.OpenWeb()

In SP2010 you should use the SPItemEventProperties.Web property instead. This performs better than OpenWeb and has no dispose issues.

hth Anders Rask

share|improve this answer

Should nobody prove me wrong, I shall presume (until I resort to ILDASM / Reflector) that the safe way in ItemEventReceivers would be to use

SPWeb _web = properties.ListItem.ParentList.ParentWeb;


if (properties.ListItem != null) SPWeb _web = properties.ListItem.ParentList.ParentWeb;


bool _shouldDispose = false;
try {_web = properties.ListItem.ParentList.ParentWeb;} catch (SPException ex) {_web = properties.OpenWeb(); _shouldDispose=true;}
share|improve this answer
fyi, depending on the type of item event, properties.ListItem could be null (i.e. ItemDeleted) – Jaap Vossers Feb 2 '10 at 19:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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