In a previous post, I wrote about a few gotchas that you may come across when doing event handlers in SharePoint. After writing that one, I’ve come across a few more. These are related to number fields.
Gotcha number one, which is not that weird actually, but is good to know about, is that number columns are always stored as doubles. I had a column defined to include numbers from 0 and up, with zero decimals. The error occurred in my event handler, when I tried to do int.Parse(properties.AfterProperties[<field name>].ToString()). This failed miserably. When inspecting the actual result of the .ToString(), it turned out to be “1.000000000000”, and not “1”, as expected.
Gotcha number two, which is a bit stranger, turned up after I had found out about gotcha number one. Both properties.AfterProperties[<field name>] and properties.ListItem[<field name>] return objects, BUT the underlying type for the AfterProperties is string, while the ListItem properties are the real type, in this case double. So, the properties.ListItem[<field name>] could be cast directly to a double, while the properties.AfterProperties[<field name>] had to go through a double.Parse(properties.AfterProperties[<field name>] .ToString()).
Well, that’s it for now. I have a few more “gotcha”-posts, and a couple of “did you know that”-posts waiting to be written, so stay tuned.



Also in some countires the numbers with Decimal are numbers separated with comma, but not a dot. So you may addup your code with Replace part as follows:
double Ao_VNK_GNK_1 = double.Parse(properties.AfterProperties["Ao_VNK_GNK"].ToString().Replace(“.”,”,”));
Otherwise Double.Parse will generate Error.