Subscribe
E-mail
Download View Codeplex Project Site
Powered by: newtelligence dasBlog 1.9.7174.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2008, Rich Finn
dasBlog MOSS template
Just started using the SPFieldLookupValue object. It makes life so much easier for retrieving values from SPFields when the field type is a lookup type.
There's a couple of constructors, but the one that takes the cake is the second one: SPFieldLookupValue(string fieldValue).
In SharePoint 2007, lookups field types (and user field types, as well) store their values as strings like this: 'FIELDLOOKUPID;#FIELDVALUE'. The FIELDLOOKUPID integer is the unique id of the SPListItem in the lookup list. If you have this value, it makes it really easy to retreive the SPListItem by calling the GetItemByID(int) method of SPList. Once you have the SPFieldLookupValue object instantiated, there are two properties - LookupId, and LookupValue.
There's a object called SPFieldUserValue which is derived from SPFieldLookupValue which is great for retrieving the SPUser object for the user selected in the user field type. The constructor I like to use is SPFieldUserValue(SPWeb, string). In this case, the LookupId property value is in fact the user's SharePoint principle id, so it makes it very easy to construct a Contact object for this user by calling the Contact.FromPrincipalID(int) method.