Thursday, January 10, 2008

Getting user profile values that support multiple value

I noticed today that the MSDN article "User Profiles Object Model Overview" has a wrong code sample for the "correct way of retrieving a user profile property value". The code sample there will not work, because the object model in sharepoind doesnt have the methods and objects the sample code is using.
Therefore - here is my correct way:

if (Profile[this.UserProfilePropertyName].Count == 1)
    return Profile[this.UserProfilePropertyName].Value.ToString();
    StringBuilder ret = new StringBuilder("");
    UserProfileValueCollection values = Profile[this.UserProfilePropertyName];
    System.Collections.IEnumerator allValues = values.GetEnumerator();
    return ret.ToString();

No comments: