Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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);

   }
share|improve this question

2 Answers 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 ?

share|improve this answer
    
Yes i think Yes, but here at SPListItem item = lstOtherList.GetItemById(2); I get null and ArgumentException wos unhandled by user code –  Grzegorz Z Oct 15 '12 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 –  Arsalan Adam Khatri Oct 15 '12 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 Oct 15 '12 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(); } } –  Arsalan Adam Khatri Oct 16 '12 at 6:39
    
call base.ItemAdding(properties); at the top... then add the new item in other list! –  Arsalan Adam Khatri Oct 16 '12 at 6:39

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/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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