In an ItemUpdated Event Receiver we were accessing two custom lists for
reading values and for that we required to return the current site in which the
event occured.
Simply writing SPSite mySite = new SPSite("http://yoursitename"); does
not make sense. Because you might don’t know where you need to deploy the Event
Receiver, hence hard-coding the Site URL is a bad practice. The below code shows
how to return current site URL.
namespace ItemUpdateFeatureReceiver
{
public class
Class1 : SPItemEventReceiver
{
private SPWeb _web;
public SPWeb myWeb
{
get
{
return
_web;
}
set
{
_web = value;
}
}
//Property that
returns a custom list named “Document Type”
public SPList CustomList1
{
get
{
SPList
myList = myWeb.Lists["Document Type"];
return
myList;
}
}
//Property that
returns a custom list named “Document Sub-Type”
public SPList CustomList2
{
get
{
SPList
myList = myWeb.Lists["Document Sub-Type"];
return
myList;
}
}
public override void
ItemUpdated(SPItemEventProperties
properties)
{
//Returns the current site in which event
occured
myWeb = properties.OpenWeb();
//your code
}