SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am accessing the user profile property from code but it returns null value as well as false in the boolean type property.

My code is:

if (web != null)

    SPList list = ListHelper.GetListByUrl(web.Lists,ListNames.DepartmentsUrl);

    if (list != null)
        SPQuery query = new SPQuery();
        query.Query = string.Format(CamlQueries.Department.QueryForDepartmentUrl, properties.Web.Name);
        SPListItemCollection coll = list.GetItems(query);

        if (coll != null)
            SPListItem item = coll[0];
            var taxonomyField = item.Fields.GetFieldByInternalName(FieldNames.Department) as TaxonomyField;
            var fieldValue = item[taxonomyField.Id] as TaxonomyFieldValue;
            SPServiceContext contex = SPServiceContext.GetContext(properties.Web.Site);
            if (contex != null)
                 UserProfileManager upm = new UserProfileManager(contex);
                 #region Change User Profile Properties
                 if (upm != null)

                            UserProfile u = upm.GetUserProfile(user[0]);

                            if ((bool)u[FieldNames.Manager].Value)
                             properties.ErrorMessage = "Manager is already assigned to other department";
                            properties.Status = SPEventReceiverStatus.CancelWithError;
                            properties.Cancel = true;

                                if (groupAdded.Name.EndsWith(UserGroups.Managers.Name))

Here in the condition :if ((bool)u[FieldNames.Manager].Value) I am getting false but in the user profile property from central admin it is true.

What should I do?

N.B. The property's privacy is set to Everyone.

share|improve this question

Try this : u[PropertyConstants.Manager].Value; instead of u[FieldNames.Manager].Value .

Else How to get user profile property value when privacy for property set to "Private" (only me)

share|improve this answer
Thanks for reply sir, but the [FieldNames.Manager] returns the name of the custom property of user profile. So how would I get that custom property in property. Actually manager is boolean in my case – users1100 Oct 23 '13 at 4:09
Not sure i understood you correctly . But I have a bool custom property ABCD-DEFGFG with Display Name as ABC .I use the below code . UserProfileValueCollection valuesr = profile["ABCD-DEFGFG"]; bool VOlla = (bool)valuesr.Value; if (VOlla) { i++; } else{ } – Nikhil Jangle Oct 23 '13 at 17:49

I guess you need to add "AllowUnsafeUpdates" in your code. Adding this might help.


Hope this helps. :)

share|improve this answer
I see no updates being made, how will this help? – Robert Lindgren Oct 22 '13 at 15:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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