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

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

       } 

   }
share|improve this question
    
Im'mining about this code 'item["ID z Czas Pracy Wpisy"] = properties.AfterProperties["Id"];' –  Grzegorz Z Oct 25 '12 at 12:44

2 Answers 2

up vote 2 down vote accepted

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();
}
share|improve this answer

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

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.