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 ?