Getting the SPWeb object of Site in the Itemdeleting event in Sharepoint

 

Hi,

 

A few days ago I was working with Item deleting event in the share point. I had to update some of the referenced items in the other records in the same list when an item was being deleted.

 

But I realized the a major problem in doing so since the SPContext.Current does not provide us with the context of the site in the overridden ItemDeleting event.

 

Even the new SPSite(properties.SiteId) failed to generate an object of the site. I know I can easily create the SPSite object by hard-coding the Site URL, but that is something that I did not wanted to do.

 

Then one of my friends told me to use the following code to get the SPWeb object.

 

SPWeb web = properties.ListItem.Web

 

After getting the SPWeb object the work was easily done.

 

Vikram

No Comments