0

We have a process that extracts User Profiles from the User Profile Service Application

The problem is we need only the user Profiles that have been modified in the last one week

How should we approach it ?

1

To achieve your goal you can use UserProfileManager.GetChanges method and test if the change made is before 7 days using ProfileBaseChange.EventTime property

private static void Main(string[] args)
{
    // TODO: Set Your target SPSite Url
    using (SPSite site = new SPSite("Your Site Url"))
    {
        try
        {

        SPServiceContext serviceContext = SPServiceContext.GetContext(site);

        //initialize user profile config manager object
        UserProfileManager profileConfigManager = new UserProfileManager(serviceContext);

            UserProfileChangeCollection collection = profileConfigManager.GetChanges();
            foreach (UserProfileChange change in collection)
            {
                // Filter user Profiles that have been modified in the last one week
                if (change.EventTime > DateTime.Now.AddDays(-7))
                {
                    Console.WriteLine("\n*-- Change made this week --*\n");

                    Console.WriteLine("AccountName : " + change.AccountName);
                    Console.WriteLine("ChangeType : " + change.ChangeType);
                    Console.WriteLine("EventTime : " + change.EventTime);
                    Console.WriteLine("Id : " + change.Id);
                    Console.WriteLine("ObjectType : " + change.ObjectType); 
                }
                else
                {
                    Console.WriteLine("\n*-- Old Change --*\n");

                    Console.WriteLine("AccountName : " + change.AccountName);
                    Console.WriteLine("ChangeType : " + change.ChangeType);
                    Console.WriteLine("EventTime : " + change.EventTime);
                    Console.WriteLine("Id : " + change.Id);
                    Console.WriteLine("ObjectType : " + change.ObjectType);

                }

            }
        }
        catch (Exception exception)
        {
            Console.WriteLine(exception.Message);
        }
    }

    Console.ReadKey();
}

And the result :

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.