I am a sharepoint 2013 beginner and inherited this project so bear with me . Trying to update a field in a documentlibrary which is of type SPFieldUserValueCollection . The c#code looks like this:

public static void UpdateMultiUserField(SPListItem item, string fieldName, SPUser user)
            SPFieldUserValueCollection values = (SPFieldUserValueCollection)item[fieldName];

            if (values == null)
                values = new SPFieldUserValueCollection();

            values.Add(new SPFieldUserValue(item.ParentList.ParentWeb, user.ID, user.Name));

            item[fieldName] = values;

Currently when I check the values of the Field after updating I can see the users listed with their Name properties. How do I change the code to list their LoginName properties instead? I tried:

  values.Add(new SPFieldUserValue(item.ParentList.ParentWeb, user.ID, user.LoginName));

Since it is a user field you can change the display value to login name from the list settings then click on desired column in the column list. This will open column settings here you can select whether you want to display login name or email id or name.

Hope this information will be useful for you

All the best!!!

  • Where can I find those list settings? – bier hier May 13 '18 at 8:10
  • 1
    Open your list in browser, select any list item in ribbon click on list tab under list tab on the right end there would be button for list settings – Shridhar J Joshi May 13 '18 at 8:14
  • There is no column called LoginName – bier hier May 13 '18 at 8:16
  • I don't understand why there was a downvote on this answer, while it seems perfectly correct to me. – Evariste May 13 '18 at 10:04

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.