ItemAdded Event Sometimes Cannot Get AfterProperties

-ed Event such as "ItemAdded" method sometimes cannot get AfterProperties which is added by Document Parser from a list item. I heard this from one of my colleagues and I haven't reproduced it yet.
Document Parser enables to binding the document properties to list item's columns. Here is the sample :

  • Click New Document.

  • Fill in the form and click Save.
  • You can see the form data were binded to list item's columns.

We usually write event handler code which gets list item's column data when an item is added. But sometimes we cannot get item's column data by using AfterProperties.
This is because -ed event (ItemAdded) runs asynchronously. That means -ed event and document parser which add data to column run different threads. In this case, what we need to do is adding Thread.Sleep in -ed event code. Thread.Sleep is specified in milliseconds unit. 
 Here is the sample :

public override void ItemAdded(SPItemEventProperties properties)
    string name = (string)properties.AfterProperties["Name"];
    string title = (string)properties.AfterProperties["Title0"];
    string discription = (string)properties.AfterProperties["Discription"];
    SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("ItemAdded", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, "ItemAdded" + " " + name + " " + title + " " + discription, "ItemAdded" + " " + name + " " + title + " " + discription);

I love Terje Sorgjerd's creations. They are my favorites. So beautiful, so creative. I'll share his another creation.

No comments:

Post a Comment