0

How Can I choose a lists in Event Receivers propeties. Please help. I Know i should set in XML <Receivers ListTemplateId="100">, but how I should choose one from another ? Please help me

I want to puts one content to another but i don't know haw choose:

       public override void ItemAdding(SPItemEventProperties properties)
   {

       properties.AfterProperties["Numer Kontraktu/Oferty/Szansy"] = properties.AfterProperties["Numer Kontraktu/Oferty/Szansy"];
       properties.AfterProperties["Pracownik"] = properties.AfterProperties["Pracownik"];
       properties.AfterProperties["Dzień"] = properties.AfterProperties["Dzień Start"];

       base.ItemAdding(properties);

   }

2 Answers 2

2

Grzegorz Z,

I think now I get your question, do something like this:

public override void ItemAdding(SPItemEventProperties properties)
{
   base.ItemAdding(properties);
   if (properties.List.Title == "ListName")
   {
      SPList lstOtherList = properties.Web.Lists["AnotherListName"];
      SPListItem item = lstOtherList.GetItemById(2);

      item["Numer Kontraktu/Oferty/Szansy"] = properties.AfterProperties["Numer Kontraktu/Oferty/Szansy"];
      item["Pracownik"] = properties.AfterProperties["Pracownik"];
      item["Dzień"] = properties.AfterProperties["Dzień Start"];
   }
}

Is this something you are trying to do? Update another item in another list with the content of the item being added ?

7
  • Yes i think Yes, but here at SPListItem item = lstOtherList.GetItemById(2); I get null and ArgumentException wos unhandled by user code
    – Grzegorz Z
    Commented Oct 15, 2012 at 12:31
  • It was just an example, replace 2 with the Id of the item you want to get.. GetItemById(ItemId); Also, here you can use SPQuery and write CAML to query the item you want from another list Commented Oct 15, 2012 at 12:39
  • I think I'm nere to get in tought to solution thanks You :) ` if (properties.List.Title == "Wpisy") { SPList lstOtherList = properties.Web.Lists["Szczegoly"]; SPListItem item = lstOtherList.AddItem(); item["Kontrakt"] = properties.AfterProperties["Kontrakt1"]; item["Pracownik"] = properties.AfterProperties["Pracownik"]; item["Dzien"] = properties.AfterProperties["DzienStart"]; item.Update(); } base.ItemAdding(properties); }` but same fields are don't come.
    – Grzegorz Z
    Commented Oct 15, 2012 at 14:03
  • base.ItemAdding(properties); if (properties.List.Title == "Wpisy") { SPList lstOtherList = properties.Web.Lists["Szczegoly"]; SPListItem item = lstOtherList.AddItem(); item["Kontrakt"] = properties.AfterProperties["Kontrakt1"]; item["Pracownik"] = properties.AfterProperties["Pracownik"]; item["Dzien"] = properties.AfterProperties["DzienStart"]; item.Update(); } } Commented Oct 16, 2012 at 6:39
  • call base.ItemAdding(properties); at the top... then add the new item in other list! Commented Oct 16, 2012 at 6:39
1

To bind a receiver to a specific list, You can also set List Url in Receivers tag as:

<Receivers ListUrl="Lists/Tasks">

For this to work, your feature should have scope=web.

Check here for more details: http://extreme-sharepoint.com/2011/12/27/event-receivers-sharepoint-2010/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.