Sharepoint Getting SPWeb object in Itemdeleting event through properties
Posted on 10/16/2008 7:17:39 AM
in #SharePoint
Hi,/o:p>/SPAN>/P>
/o:p>/SPAN>/P>
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. /o:p>/SPAN>/P>
/o:p>/SPAN>/P>
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. /o:p>/SPAN>/P>
/o:p>/SPAN>/P>
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. /o:p>/SPAN>/P>
/o:p>/SPAN>/P>
Then one of my friends told me to use the following code to get the SPWeb object./o:p>/SPAN>/P>
/o:p>/SPAN>/P>SPWeb web = properties.ListItem.Web/o:p>/SPAN>/PRE>
After getting the SPWeb object the work was easily done. /o:p>/SPAN>/P>
/o:p>/SPAN>/P>
Vikram/o:p>/SPAN>/P>
|