don't instantiate SPWeb,SPSite,SPlist or SPListItem Objects with in event reciver. instantiating these Objects in side the event Receiver can cost you more roundtrips to the database.
don't code like that
using (SPSite osite = new SPSite(properties.WebUrl))
{
using (SPWeb sweb = osite.OpenWeb())
{
SPList list = sweb.Lists[properties.ListId];
SPListItem item = list.GetItemByUniqueId(properties.ListItemId);
}
}
Code like that
// Retrieve SPWeb and SPListItem from SPItemEventProperties instead of
// from a new instance of SPSite.
SPWeb web = properties.OpenWeb();
// Operate on the SPWeb object.
SPListItem item = properties.ListItem;
// Operate on an item.
SHAREPOITN 2010 Event Receivers Tip
Monday, April 8, 2013
Posted by Usama Wahab Khan at 12:46 AM
Labels: SharePoint 2010
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment