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
}
1 comments:
This blog is having the general information. Got a creative work and this is very different one.We have to develop our creativity mind.This blog helps for this. Thank you for this blog. This is very interesting and useful.
Sharepoint Training in Chennai
Post a Comment