Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 13 down vote accepted

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

MSDN: SPFieldLookupValue

or the SPFieldMultiChoiceValue class:

MSDN: SPFieldMultiChoiceValue

share|improve this answer
    
I happen to have written an article on this very subject a few moments ago. :) tsstsst.com/?p=44 –  Stuart Pegg Aug 16 '11 at 20:51
add comment

you can write own function like this

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

This solve your problem

share|improve this answer
    
-1 For that to work you have to know the delimiter –  Johan Leino Apr 13 '11 at 10:02
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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