Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 ?

share|improve this question
    
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 –  Matthew McDermott Sep 30 '13 at 21:52

1 Answer 1

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.

share|improve this answer
    
If the above answer was useful and correct, please mark it as answer, so that it will be helpful to others too. –  Karthik Jaganathan Oct 4 '13 at 18:35

Your Answer

 
discard

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.