Hi. I have event receiver i've created for a specific list for ItemAdded event. this is a CategoryLookup list. this list updated a choice field of another list, myList.
But the ItemAdded event receiver fires the actions of this event receiver for every list in this colllection. I did research and found suggestions to add this event receiver to the list on FeatureActivation. which i did. it didn't help though: the item gets added to teh Category of CategoryLookup list everitime item is added to any list...
Below is the code of both Feature Activation and ItemAdded. I hope someone can point out what i'm doing wrong... thank you much in advance.
this event receiver is created within the List:
namespace myNameSpace.ManageCategories
{
/// <summary>
/// List Item Events
/// </summary>
public class ManageCategories : SPItemEventReceiver
{
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
string strCategory = string.Empty;
SPListItem _currentItem = properties.ListItem;
strCategory = (String)_currentItem["Title"].ToString();
SPWeb web = properties.Web;
web.AllowUnsafeUpdates = true;
SPList list = web.Lists.TryGetList("myList");
if (list != null)
{
SPFieldChoice choiceField = (SPFieldChoice)list.Fields["Category"];
choiceField.Choices.Add(strCategory);
choiceField.Update();
}} }}
the code below is FeatureActivation:
public class myEventReceiver : SPFeatureReceiver
{
// Uncomment the method below to handle the event raised after a feature has been activated.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
try
{
//Adds the overridden ItemUpdated Event Receiver to a list
SPSite site = (SPSite)properties.Feature.Parent;
SPWeb web = site.RootWeb;
SPList lst = web.Lists["LookupCategories"];
string asmName ="myAssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d694dbf37cc0d2c1";
string itemReceiverName = "myNameSpace.ManageCategories";
lst.EventReceivers.Add(SPEventReceiverType.ItemAdded, asmName, itemReceiverName);
}
catch (Exception ex)
{
Log.Error(ex);
}
}