0

I try this in ItemAdding, but it isn't work(Gives Null): public override void ItemAdding(SPItemEventProperties properties) { base.ItemAdding(properties);

       if (properties.List.Title == "Wpisy")
       {
           SPList lstOtherList = properties.Web.Lists["Szczegoly"];

           DateTime dzienStart = new DateTime();
           DateTime dzienStop = new DateTime();
           dzienStart = Convert.ToDateTime(properties.AfterProperties["DzienStart"]).ToUniversalTime();

           dzienStop = Convert.ToDateTime(properties.AfterProperties["DzienStop"]).ToUniversalTime();

           while(dzienStart<=dzienStop){


               if (dzienStart.DayOfWeek.ToString() ==  "Saturday" || dzienStart.DayOfWeek.ToString() == "Sunday")
               {

                   dzienStart = dzienStart.AddDays(1.0);
                   continue;
               }

               {              
                   SPListItem item = lstOtherList.Items.Add();
                   item["Kontrakt"] = properties.AfterProperties["Kontrakt1"];
                   item["Pracownik"] = properties.AfterProperties["Pracownik1"];
                   item["Dzien"] = dzienStart;
                   item["Procenty"] = properties.AfterProperties["Procenty"];
                   **item["ID z Czas Pracy Wpisy"] = properties.AfterProperties["Id"];**
                   dzienStart = dzienStart.AddDays(1.0);
                   item.Update();
               }
           }

       } 

   }
1
  • Im'mining about this code 'item["ID z Czas Pracy Wpisy"] = properties.AfterProperties["Id"];'
    – Grzegorz Z
    Commented Oct 25, 2012 at 12:44

2 Answers 2

2

According to Alex's great list of BeforeProperties/AfterProperties in Event Receivers you should not be able to get any properties in ItemAdding.

However you can get the item ID in ItemAdded, like this:

public override void ItemAdded(SPItemEventProperties properties)
{
  var someList = properties.Web.Lists["SomeList"];
  var item = someList.Items.Add();
  item["SomeID"] = properties.ListItemId;
  item.Update();
}
0

It doesn't work, it's only add One element, and in the last record, and I must add them to the all elements, in wchich I adding. Here is screen of error Added items: enter image description here

Here is all the code:

       public override void ItemAdded(SPItemEventProperties properties)
   {

       base.ItemAdded(properties);
       if (properties.List.Title == "Wpisy")
       {
           var someList = properties.Web.Lists["Szczegoly"];
           var item = someList.Items.Add();
           item["ID z Czas Pracy Wpisy"] = properties.ListItemId;
           item.Update();
       }
   }

It's almost the same like Yours. It's only added last element, and only ID

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.