Hi and thanks for looking!
I have inherited an old .NET project based on SharePoint 2007 and have designed and external core library which merely accesses SP data, therefore making SP just a backend. Yes, I know it would be better to migrate to SQL, but the client doesn't agree.
The previous developers used a simple read method to read the data in a SP list:
SPList list = CurrentRootWeb.Lists["SomeListName"];
And then they access list properties through a dictionary of sorts (i.e. for each item in list, get item["SomeValue"]).
I am not skilled in SharePoint, so I don't know if this is the most efficient manner to go about accessing it's data.
How do I read LookUp fields with multiple values in SharePoint?
Every property they request seems to want a string in return. So item[SomeString]
is okay, but item[SomeList]
makes everything barf! I would have thought that a multi-value lookup list column comes in as a serialized or delimited string holding the selected values (example: "red;blue;green"). What am I missing?
Thanks!
If you are specifically interested in LookUp fields with multiple values not just MultiChoice feilds, then following code should help:
item.Fields["LookFieldName"].Type == SPFieldType.Lookup;
SPFieldLookup LookUpField = item.Fields["LookFieldName"] as SPFieldLookup;
if (LookUpField.AllowMultipleValues)
{
SPFieldLookupValueCollection valueCollection = item[Field.Id] as SPFieldLookupValueCollection;
string[] arrLookupValues = (from SPFieldLookupValue val in valueCollection select val.LookupValue).ToArray<string>();
}