SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 fetching the user data from the user profile service. I have created a custom property for EmpId. When I try to access its value NullReferenceException is thrown.

How can I access the value from the custom property?

Please guide.

share|improve this question
Can you check your custom property Default Privacy Setting.Set it to everyone and try again – Vishal_Sharepoint Apr 18 '12 at 7:14
up vote 0 down vote accepted

Example of usage

SPServiceContext serviceContext = SPServiceContext.GetContext(ctx.Site);

            // Then load the UserProfileManager
            UserProfileManager mngr = new UserProfileManager(serviceContext);

            // Get the user’s profile
            UserProfile currentProfile = mngr.GetUserProfile(true);

            // If the user has a profile, get the SocialTagManager 
            if (currentProfile != null)
                //Do your stuff

Also have a look here (NOT best practice but it'll get you started) and here for custom properties

Do remember to run a FULL Syncro or otherwise you custom property might not be having values in it already!

Hope it helps, C:\Marius

share|improve this answer
thanks a lot all of u for ur help :) – Mansi Desai Apr 19 '12 at 9:03
Definitely perform the null check on the returned property value. That gets me every time. – Matthew McDermott Apr 19 '12 at 10:12

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.