Вопрос

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.

Это было полезно?

Решение

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;

Другие советы

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top