Tuesday, September 27, 2011

Get UserProfile using UserProfileManager in SharePoint and ASP.NET application

Fetch Contact details from Active directory and SharePoint contacts using User profile service

public ArrayList SearchingFromUserProfile(string key)
//getting the URL of Central Admin.
Microsoft.SharePoint.Administration.SPAdministrationWebApplication centralWeb = SPAdministrationWebApplication.Local;
string centraladmin = centralWeb.GetResponseUri(Microsoft.SharePoint.Administration.SPUrlZone.Custom).AbsoluteUri.ToString();

ArrayList result = new ArrayList();

//Initallizing the UserProfileManager.
using (SPSite site = new SPSite(centraladmin))
SPServiceContext context = SPServiceContext.GetContext(site);
UserProfileManager userprofilemanager = new UserProfileManager(context);

//Getting WorkEmail of all the Users Resolved.
foreach (UserProfile profile in userprofilemanager)
object property = profile[PropertyConstants.WorkEmail];
if(property != null && property != "")
return result;

1 comment:

  1. I am impressed. I don't think Ive met anyone who knows as much about this subject as you do. You are truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog you have got here. User Profile Chinnagounder Thiruvenkaam