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

Do someone know if it's possible to attach an event receiver to profile updates?

The goal would be to update an external system (such as a CRM) when a user is updating his profile.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

As James said, you could create a timer job to sync profile changes with the external system. But, to detect the changes in user profile properties, I would suggest you to look into UserProfileChangeCollection because it contains a complete log of changed user profiles.

using (SPSite site = new SPSite("http://server1"))
           {
               SPServiceContext serviceContext = SPServiceContext.GetContext(site.WebApplication.ServiceApplicationProxyGroup, SPSiteSubscriptionIdentifier.Default);
               UserProfileManager profileConfigManager = new UserProfileManager(serviceContext);
               try
               {
                   UserProfileChangeCollection collection = profileConfigManager.GetChanges(query);
                   foreach (UserProfileChange change in collection)
                   {
                       Console.WriteLine(change.AccountName);                               
                       if (change is UserProfileSingleValueChange)
                       {
                           UserProfileSingleValueChange propertyChange = (UserProfileSingleValueChange)change;
                           Console.WriteLine(propertyChange.ProfileProperty.Name);
                       }
                   }
               }
               catch (UserNotFoundException)
               {
               }

Read more on MSDN and Example

share|improve this answer

Not really - the User Profile properties aren't stored in a list (which is where Event Receivers are registered) - they're all stored in the User Profile Database which is managed by the User Profile Service Application.

If you want to sync profile changes with an external system, you can write a Timer Job to look up the user profile properties and synchronise them with your external system. You would configure the timer job to run at an interval, and maybe use the User Profile Change Log to find out what's been changed.

share|improve this answer
    
+1 for timer job sync with external system. –  Falak Mahmood Jul 14 '12 at 11:49
    
@James Love: Thanks for your answer. I credited Falak Mahmood because he was providing more details. However, if I could have split the points, I would have. –  Jaepetto Jul 14 '12 at 18:41

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.