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;
  • By the way, current SPDisposeCheck fails to detect this undisposed SPWeb scenario. Jan 25, 2010 at 9:23

2 Answers 2


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


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;}
  • 2
    fyi, depending on the type of item event, properties.ListItem could be null (i.e. ItemDeleted) Feb 2, 2010 at 19:31

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.