2

How could i get only the username from my list? Right now my username gets displayed as a string so there are some characters in front the username that should not be there? 18;#Bart Simpsson like this it gets displayed when getting the data from my list, My field is of type user

Here is my code

Guid fieldID2 = item.Fields.GetFieldByInternalName("FirstNameLastName").Id;
string valueField2 = item[fieldID2].ToString();
Label1.Text=valueField2;

1 Answer 1

5

You can use below code to extract the SPUser object

string valueField2 = item[fieldID2].ToString();
SPFieldUserValue userField = (SPFieldUserValue)item.Fields[fieldID2].GetFieldValue(valueField2);
SPUser user= userField.User;

Now you can access all properties of SPUser Object

Example user.LoginName

1
  • 1
    Nice... You beat me to it :)
    – Muhammedh
    Commented May 12, 2015 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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