4

In querying the properties of a list item, I found that returning the value of a people or group field that the value would be returned in the form

1;#George Grainger

Using the code:

properties.ListItem["Staff Member"].ToString();

I've worked around the issue, by splitting into 2 strings, but I was wondering if anyone would know of a way to return the value without the ;# preceding the desired return value?

Note: I realise I could dig through the current web, list and item to query the fieldValue.User.Name, however this is somewhat resource expensive, and I was hoping for a "cleaner" way.

7

Use below code to get User name:

new SPFieldLookupValue(properties.ListItem["Staff Member"].ToString()).LookupValue;

For User ID:

new SPFieldLookupValue(properties.ListItem["Staff Member"].ToString()).LookupId;
1

My understanding is that by using:

properties.ListItem["Staff Member"].ToString();

You are going to be returned their userID and username, so it will always be returned separated by ;#.

You're probably already using something like:

properties.ListItem["Staff Member"].ToString().split(";#")[1];

To return the username on it's own. You should compare the performance of that against fieldValue.User.Name and see which is less taxing.

There might be another field value I am missing that you could use in it's place, but I have always just split their ID from the name.

  • This was the workaround that I was alluding to in my question, I was hoping for the "proper" way to do it – George Grainger Feb 12 '16 at 10:43

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.