Posts Tagged ‘Gotcha’

More SharePoint Event Handler Gotchas

By Andreas Finne
Monday, December 20, 2010
Posted in Articles

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.

SharePoint Event Handler Gotchas

By Andreas Finne
Wednesday, April 21, 2010
Posted in Blog

In a previous SharePoint project, I implemented a few event handlers that get called whenever an item in a list gets changed (or added/deleted). There were a few problems along the way that took a bit of searching before I found solutions. This post documents a few of the things that are good to know.

Read More

SQL access with integrated security from SharePoint

By Andreas Finne
Thursday, April 15, 2010
Posted in Code

When creating custom webparts or other custom features in SharePoint that retrieves data from a SQL server, there are a few gotchas and pitfalls that you should be aware of. I spent a few hours battling a couple of problems, so I thought I’d document the things I found out here to spread the knowledge.

Read More

SharePoint Feature Dependencies

By Andreas Finne
Monday, December 14, 2009
Posted in Blog

When declaring a feature, you can add an <ActivationDependencies> section to your feature.xml file. Here you can list the features your own feature is depending on.

According to the documentation on activation dependencies (http://msdn.microsoft.com/en-us/library/aa543162.aspx), the depending features get automatically activated if they are in the same scope: “If a Feature is dependent on another Feature at the same scope, and the second Feature is not activated when the first one is activated, Windows SharePoint Services activates the second Feature

This is incorrect!

The second feature is activated automatically only if it is hidden!