سؤال

When you get an SPListItemCollection from a SPList.GetItems(SPQuery) request, and the items have SPFieldUser or SPFieldLookup fields, what is the sexy way to get typed values, not the item["Field"].ToString().Split('#')[1] way, please?

هل كانت مفيدة؟

المحلول

new SPFieldLookupValue(item["FieldName"] as String).LookupValue

you probably want to check if item["FieldName"] is not null or empty before doing this.

SPFieldUserValue works similarly, but you need to pass in an SPWeb into the constructor, which you can retrieve from your SPListItem using SPListItem.ParentList.ParentWeb

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى sharepoint.stackexchange
scroll top