Sharepoint Getting SPWeb object in Itemdeleting event through properties

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


Share this post   Email it |  digg it! |  reddit! |  bookmark it!

Feedback

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 
Copyright © 2006 - 2009 Vikram Lakhotia