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

With the Code below i'm able to get access to a custom profile property which i created ("Qualifications"). Somehow i dont get it how to get access to the stored information for the custom property field..

using System;
    using System.ComponentModel;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebControls;
    using Microsoft.SharePoint.Security;
    using Microsoft.SharePoint.Portal;
    using Microsoft.Office.Server;
    using Microsoft.Office.Server.UserProfiles;
    using System.Diagnostics;

    namespace CV.CV
        public class CV : WebPart

            Property propQualifications = null;
            string strQualifications = "";

            protected override void OnPreRender(EventArgs e)
                var test = GetUserProperties();

            public Microsoft.Office.Server.UserProfiles.PropertyCollection GetUserProperties()
                Microsoft.Office.Server.UserProfiles.PropertyCollection oPropertyCollection = null;

                System.Security.PermissionSet ps = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);

                Microsoft.SharePoint.SPServiceContext serviceContext = Microsoft.SharePoint.SPServiceContext.Current;
                Microsoft.Office.Server.UserProfiles.UserProfileManager upm = new Microsoft.Office.Server.UserProfiles.UserProfileManager(serviceContext);

                oPropertyCollection = upm.PropertiesWithSection;

                propQualifications = oPropertyCollection.GetPropertyByName("Qualifications");
                strQualifications = propQualifications.ToString();


                return oPropertyCollection;
share|improve this question
up vote 4 down vote accepted

You need to get a user profile object and once you have the object you can access the profile's properties, including the custom ones. For example:

        UserProfileManager upm = new UserProfileManager(SPServiceContext.GetContext(site));
        UserProfile p = upm.GetUserProfile("accountname");
        object value = p["propertyname"][0];
share|improve this answer
I can't debug this Part.. it shows me the disassembly.. so its a little bit hard to check if its working or not.. – Peter Aug 2 '11 at 14:24
I'm not sure I'm following you. – Rob D'Oria Aug 2 '11 at 18:57
When i'm debugging your code, which i added in my webpart. I can't debug these commands. I have the posibility to see the disassembly since the debugger wants to debug on server-side – Peter Aug 2 '11 at 20:32
I had a Breakpoint on object value = p["propertyname"][0]; so the debugger had an error, removed it and now everything works fine! – Peter Aug 3 '11 at 7:34

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.