Question

I have a multiple lookup field, and when I do this:

string myValue = oItem["MyLookupField"];

I get this string back:

[id];#[displayText];#[id];#[displayText]

or a real example:

"5;#C3;#15;#P3"

as you can see not the most logical string to split. Surely there must be a better way to get a splitable string back from sharepoint for a lookup field.

I would expect something like:

"5;C3|15;P3" (for example)

Anyone know how to get a better string back for a lookup field?

Was it helpful?

Solution

Instead of parsing them manually, try using the SPFieldLookupValue class instead:

MSDN: SPFieldLookupValue

or the SPFieldMultiChoiceValue class:

MSDN: SPFieldMultiChoiceValue

OTHER TIPS

The delimiter cannot be changed and is found in the SPFieldMultiChoiceValue.Delimiter property.

you can write own function like this

var Result = Regex.Split(data, ";#", RegexOptions.ExplicitCapture) .ToList().aggregate((x,y)=>x+";"+y+"|");

This solve your problem

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top