Get Reference to Current Web in ItemDeleted Event Handler

One of those ones I always forget! Unfortunately the normal processes of getting the current SPWeb dont apply in the ItemDeleted Event Handler as properties.ListItem is null. Fortunately properties.WebUrl can be used to create a new connection back to the web as SPSite then simple OpenWeb():

public override void ItemDeleted(SPItemEventProperties properties)
{
    using(SPSite oSite = new SPSite(properties.WebUrl))
    {
        using(SPWeb oWeb = oSite.OpenWeb())
        {
            //do something
        }
    }
}

Leave a Reply