My new blog present here.

Featured Post

Insights into Sitecore Search: A Definitive Introduction

A key component of digital experience management is effective information retrieval. A simplified approach is required for websites, applications, and platforms containing a lot of material so that consumers can easily get the data they require. This need is met by Sitecore, a well-known name in the field of digital experience platforms (DXPs), which provides powerful and comprehensive search functionality. We will travel into the realm of Sitecore Search in this article, learning about its capabilities, architecture , and the enormous value it offers both developers and end users. Introduction to Sitecore Search    A headless content discovery platform powered by AI , Sitecore Search enables you to build predictive and custom search experiences across various content sources. To extract and index you

Get changed user profiles in SharePoint using C#

Get all the user profiles/properties which are modified since yesterday date or any datetime interval:

With the help of UserProfileManager class (Microsoft.Office.Server.UserProfiles), we can access properties of user profile and changed profile which are modified since yesterday date or any datetime interval.
In this example we will access different components of UserProfileManager :


using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using System.Web;
using System.Collections;

namespace UserProfilesOMApp
{
class Program
{
static void Main(string[] args)
{

using (SPSite site = new SPSite("http://amitkumarmca04.blogspot.com"))
{
ServerContext context = ServerContext.GetContext(site);
UserProfileManager profileManager =
new UserProfileManager(context);

//Fetch all user profile properties
Microsoft.Office.Server.UserProfiles.PropertyCollection props = profileManager.Properties;
//Print all user profile properties


Console.WriteLine("_______________________Start:Print all user profile properties.");

foreach (Property prop in props)
{
Console.WriteLine(prop.Name);
}
Console.WriteLine("_______________________End:Print all user profile properties.");


//Find user profile changes.

// this gets some subset of changes to a user profile, changed 5 days before
DateTime startDate =
DateTime.UtcNow.Subtract(TimeSpan.FromDays(5));

/* If we want to access changes after "4/30/2011 11:33:47 PM" then we can use below mentioned code:

StartTime="5/30/2010 11:33:47 PM"
System.TimeSpan dateDiff = DateTime.UtcNow.Subtract(Convert.ToDateTime(StartTime));
DateTime startDate = DateTime.UtcNow.Subtract(dateDiff);
*/

UserProfileChangeQuery changeQuery = new UserProfileChangeQuery(true, true);
changeQuery.ChangeTokenStart = new UserProfileChangeToken(startDate);
UserProfileChangeCollection changes = profileManager.GetChanges(changeQuery);
//Used to store unique user names
ArrayList arrLstUsers = new ArrayList();
foreach (UserProfileChange change in changes)
{
if (arrLstUsers != null && !arrLstUsers.Contains(change.AccountName))
{
//Add user to array list
arrLstUsers.Add(change.AccountName);
//Print chagned profile user name
Console.Write(change.AccountName);
}
}
Console.Read();
}
}
}
}

Comments

Popular posts from this blog

Sitecore GraphQL Queries

Twenty 20 Masti:

Sitecore Experience Edge GraphQL Queries