here is the problem. I have a form library that uses Infopath as form. It has an event receiver. This was done by someone else. I was trying to get the beforeProperties, afterProperties or ListItem of the item to check the values, but it is not working.
BeforeProperties is working fine in ItemUpdating, but Afterproperties and ListItem do not. they are throwing this error:"Object not set to an instance of an object".
I tried my code in another Form Library that I created myself, everything works OK. it is the same code, but in two different form libraries. they are both using infopath.
So the Form library that is built for the client is showing the same error as above when I use HttpContext.Current.Session. But it is working fine in my Form Librar.
I have no idea what should I do or change in the form library to make my code work as in my test form library.
the code is simple:
public ovverride void ItemUpdating(SPItemEventProperties properties)
{
string beforeProp = properties.BeforeProperties["CurrentOccupant"].ToString(); (this is OK)
string afterProp = properties.AfterProperties["CurrentOccupant"].ToString(); (Error above)
string a = properties.ListItem["CurrentOccupant"].ToString(); (error above)
HttpContext.Current.Session["SomeValue"] = "hello there"; (error above)
//the same code with the same field name works fine in a form library that I created myself.
}
The field name is correct because it is working correctly in beforeProperties.
Please don't come around to tell me that I have to instantiate my object.
Edit:
I saw that fields used in the Form library where I get my error are in gray color, whereas in my test Form library are blue and clickable. Could this be the cause of this error? Does it mean that the data is saved first in the xml and then is saved in the readonly field?
How can I get the data directly from xml file and compare the old and new value?
Thank you.