1

I am accessing the User Profile Property in my console application to view the current logged in user's department, where "Department" is the property of user profile.

To access the property I referred this post. My code is:

class Program
{
    static void Main(string[] args)
    {
        using (SPSite siteCollection = new SPSite("http://.............."))
        {
            using (SPWeb site = siteCollection.OpenWeb())
            {
                SPUser spUser = site.CurrentUser;
                ServerContext serverContext = ServerContext.GetContext(siteCollection);
                UserProfileManager userProfileManager = new UserProfileManager(serverContext);

                UserProfile profile = userProfileManager.GetUserProfile(spUser.LoginName);
                Console.WriteLine("Current Logged In User Department:" + profile["Department"]);
            }
        }
    }
}

I am getting the error at line: UserProfileManager userProfileManager = new UserProfileManager(serverContext); that "UserProfileApplicationNotAvailableException was unhandled".

What am I missing ?

1
  • if all you need is the current user, you can pass an emptystring rather than spUser.LoginName. As for the error, you probably don't have permission on the UPA, check Karthik's response Sep 30 '13 at 21:52
2

Few days back, I was getting "No User Profile Application available to service the request. Contact your farm administrator" error, I made sure that the User Profile Application was running correctly and it was. I already clicked on the “Administrators” button in the toolbar of the Service Application to give me Full Control, but it still wasn’t working.

Then I noticed that there is also a ‘Permissions’ button for the created user profile service in the "Manager Service Application" page. I clicked the button and saw that my current user wasn’t in the permissions box. I gave my user ‘Full Control’ and now everything works great from the console application.

Hope this helps you.

3
  • If the above answer was useful and correct, please mark it as answer, so that it will be helpful to others too. Oct 4 '13 at 18:35
  • as @Karthik said you need full control: social.technet.microsoft.com/wiki/contents/articles/…
    – Nk SP
    Jan 15 '15 at 18:50
  • This. I am in the habit of running all UserProfile administrative operations under the farm admin credentials; however, as this response describes, any account can be used so long as they have permissions on the UPS. Jan 15 '15 at 22:11

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.