Loop through SharePoint Profiles
Simple code sample showing how to retrieve profiles and their properties from a SharePoint site.
Note:
- This code is relevant only if you’re running it on the SharePoint box, ie: web part, console app. If you need to access profiles outside of the box, use web services, as detailed by Michael Bowersox’s post.
- Microsoft.Office.Server.UserProfiles reference.
- Instantiate the UserProfileManager with your site context.
- PropertyConstants for retrieval of pre-defined properties. Every profile has a handful of standard properties, but check to make sure the property contains data to avoid a possible null reference exception.
- Replace PropertyConstants with custom property name to get your custom properties.