In the MSDN article Best Practices with Event Receivers it is clearly stated:
Do not instantiate an SPWeb, SPSite, SPList, or SPListItem object within an event receiver.
The article goes on to describe how to get references to the item being updated via the event properties.
Say I need to check a value of an SPListItem
from a different SPList
and a different SPWeb
(but within the same SPSite
) to conditionally format the item triggering the event receiver.
Is this a grave sin to do this like:
using (SPSite site = new SPSite(properties.SiteId))
{
using (SPWeb web = site.OpenWeb("WebName"))
{
SPList list = web.GetList("/Path");
SPListItem item = list.GetItemById(theID);
}
}
Edited for Clarity
My questions are:
1) What issues would this cause aside from performance?
2) Does this only cause issues if you instantiate the item that triggered the event receiver or does this cause an issue if you instantiate any of these objects?