10

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?

14

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

MSDN: SPFieldLookupValue

or the SPFieldMultiChoiceValue class:

MSDN: SPFieldMultiChoiceValue

  • I happen to have written an article on this very subject a few moments ago. :) tsstsst.com/?p=44 – Stu Pegg Aug 16 '11 at 20:51
-1

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

-3

you can write own function like this

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

This solve your problem

  • -1 For that to work you have to know the delimiter – Johan Leino Apr 13 '11 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.