Archive for November, 2011

This blog has been created as a sharing medium for the unique SharePoint solutions and discoveries that can help make us all more productive. Encouraged by fellow associates, it will be used to better share with the world some of the knowledge gained through experience.

“Sawyer” is a nickname I’ve taken on for many years. Inspired by Mark Twain’s Tom Sawyer, it is a reminder of the antics and fun had by the classic literature character himself. Coincidentally, today also happens to be Mark Twain’s 176th birthday (thanks, Google, for pointing that out with your Doodle of the day).  Merriam-Webster also defines a sawyer as, “a tree fast in the bed of a stream with its branches projecting to the surface and bobbing up and down with the current.” A definition which paints a rather desirable image.


Read Full Post »

Here’s a little tidbit SharePoint Developers should watch for: The method Microsoft.SharePoint.SPFieldLookup.GetFieldValueAsHtml(Object value) requires a current context. If you are using it outside of context (i.e. SPContext.Current is null), the method will throw the error message, “Object reference not set to an instance of an object.”

I was using this method both from within a web part and within a timer job on the same field. Was surprised when the call from within the web part worked, but it didn’t work from the timer job. A look at the inner workings of GetFieldValueAsHtml(Object value) quickly revealed the problem: an unchecked reference to SPContext.Current.IsPopUI. Being that SPContext.Current is null from the timer job (timer jobs don’t operate within an HttpContext), a null reference exception is thrown when trying to get IsPopUI. Now, the Microsoft developers did put most of the work done by GetFieldValueAsHtml in a try/catch block; however, the catch only catches ArgumentException. Thus, the NullReferenceException is not handled and is thus thrown to the calling code.

It’s quite possible this will get fixed in upcoming Cumulative Updates, but was present as of the June 2011 CU. I ended up simply working around it by first checking if the field was of type SPFieldLookup and, if so, calling GetFieldValueAsText(Object value) instead. Just in case any other field types have the same context problem, I also put my call to GetFieldValueAsHtml in my own try/catch block and called GetFieldValueAsText in the catch.

Read Full Post »