The following Example will demonstrates how to get the Colleagues Updates through programatically.
we can directly use the NewsFeed Webpart in Intranet Portal refer (http://sharepointchampion.blogspot.in/2013/08/making-newsfeed-webpart-available.html)
I have created one datatable and adding the values to it.
In Presentation i am binding it to a Repeater.
public DataTable GetColleagueData()
{
try
{
using (SPSite oSite = new SPSite(SPContext.Current.Site.Url))
{
SPServiceContext context = SPServiceContext.GetContext(oSite);
UserProfileManager userProfileManager = new UserProfileManager(context);
UserProfile userProfile = userProfileManager.GetUserProfile("domainname\\UserName");
//Change the start date to get the changes from certain date
DateTime startDate = DateTime.Today.AddDays(-30);
UserProfileChangeQuery userProfileChangeQuery = new UserProfileChangeQuery(true, true);
UserProfileChangeToken userProfileChangeToken = new UserProfileChangeToken(startDate);
userProfileChangeQuery.ChangeTokenStart = userProfileChangeToken;
userProfileChangeQuery.UserProfile = true;
userProfileChangeQuery.PersonalizationSite = true;
userProfileChangeQuery.Update = true;
userProfileChangeQuery.Add = true;
userProfileChangeQuery.Delete = true;
userProfileChangeQuery.SingleValueProperty = true;
userProfileChangeQuery.MultiValueProperty = true;
userProfileChangeQuery.Colleague = true;
userProfileChangeQuery.SiteMembership = true;
userProfileChangeQuery.Anniversary = true;
DataTable dt = new DataTable();
dt.Columns.Add("UserName", typeof(string));
dt.Columns.Add("Body", typeof(string));
dt.Columns.Add("Time", typeof(string));
UserProfileChangeDictionary userProfileChangeDictionary = userProfile.GetColleagueChanges(userProfileChangeQuery);
Dictionary<long, UserProfileChangeCollection>.Enumerator userProfileChangeCollection = userProfileChangeDictionary.GetEnumerator();
while (userProfileChangeCollection.MoveNext())
{
UserProfileChangeCollection userProfileChanges = userProfileChangeCollection.Current.Value;
foreach (UserProfileChange userProfileChange in userProfileChanges)
{
DataRow drNewRow = dt.NewRow();
if (userProfileChange is UserProfileSingleValueChange)
{
UserProfileSingleValueChange propertyChange = (UserProfileSingleValueChange)userProfileChange;
if (!string.IsNullOrEmpty(Convert.ToString(propertyChange.NewValue)))
{
drNewRow["Image"] = "";
drNewRow["UserName"] = userProfileChange.ChangedProfile.DisplayName;
drNewRow["Body"] = "updated" + propertyChange.ProfileProperty.DisplayName.ToString() + propertyChange.NewValue;
drNewRow["Time"] = propertyChange.EventTime.ToString("dd/MM/yyyy");
dt.Rows.Add(drNewRow);
}
}
else if (userProfileChange is UserProfileMultiValueChange)
{
UserProfileMultiValueChange propertyChange = (UserProfileMultiValueChange)userProfileChange;
if (!string.IsNullOrEmpty(Convert.ToString(propertyChange.ChangedValue)))
{
drNewRow["UserName"] = propertyChange.ChangedProfile.DisplayName;
drNewRow["Body"] = "updated" + propertyChange.ProfileProperty.DisplayName + propertyChange.ChangedValue;
drNewRow["Time"] = propertyChange.EventTime.ToString("dd/MM/yyyy");
dt.Rows.Add(drNewRow);
}
}
else if (userProfileChange is UserProfileWebLogChange)
{
UserProfileWebLogChange listChange = (UserProfileWebLogChange)userProfileChange;
}
}
}
return dt;
}
}
catch (Exception ex)
{
////logging
}
}
We will not get the Result , as we get in Newsfeed of MySite.Writing this post to let you know we have this approach also.
Remarks: I am trying to get the Colleague Picture also and bind to datatable , but i didn't get that.
The final Look
Thank you.
we can directly use the NewsFeed Webpart in Intranet Portal refer (http://sharepointchampion.blogspot.in/2013/08/making-newsfeed-webpart-available.html)
I have created one datatable and adding the values to it.
In Presentation i am binding it to a Repeater.
public DataTable GetColleagueData()
{
try
{
using (SPSite oSite = new SPSite(SPContext.Current.Site.Url))
{
SPServiceContext context = SPServiceContext.GetContext(oSite);
UserProfileManager userProfileManager = new UserProfileManager(context);
UserProfile userProfile = userProfileManager.GetUserProfile("domainname\\UserName");
//Change the start date to get the changes from certain date
DateTime startDate = DateTime.Today.AddDays(-30);
UserProfileChangeQuery userProfileChangeQuery = new UserProfileChangeQuery(true, true);
UserProfileChangeToken userProfileChangeToken = new UserProfileChangeToken(startDate);
userProfileChangeQuery.ChangeTokenStart = userProfileChangeToken;
userProfileChangeQuery.UserProfile = true;
userProfileChangeQuery.PersonalizationSite = true;
userProfileChangeQuery.Update = true;
userProfileChangeQuery.Add = true;
userProfileChangeQuery.Delete = true;
userProfileChangeQuery.SingleValueProperty = true;
userProfileChangeQuery.MultiValueProperty = true;
userProfileChangeQuery.Colleague = true;
userProfileChangeQuery.SiteMembership = true;
userProfileChangeQuery.Anniversary = true;
DataTable dt = new DataTable();
dt.Columns.Add("UserName", typeof(string));
dt.Columns.Add("Body", typeof(string));
dt.Columns.Add("Time", typeof(string));
UserProfileChangeDictionary userProfileChangeDictionary = userProfile.GetColleagueChanges(userProfileChangeQuery);
Dictionary<long, UserProfileChangeCollection>.Enumerator userProfileChangeCollection = userProfileChangeDictionary.GetEnumerator();
while (userProfileChangeCollection.MoveNext())
{
UserProfileChangeCollection userProfileChanges = userProfileChangeCollection.Current.Value;
foreach (UserProfileChange userProfileChange in userProfileChanges)
{
DataRow drNewRow = dt.NewRow();
if (userProfileChange is UserProfileSingleValueChange)
{
UserProfileSingleValueChange propertyChange = (UserProfileSingleValueChange)userProfileChange;
if (!string.IsNullOrEmpty(Convert.ToString(propertyChange.NewValue)))
{
drNewRow["Image"] = "";
drNewRow["UserName"] = userProfileChange.ChangedProfile.DisplayName;
drNewRow["Body"] = "updated" + propertyChange.ProfileProperty.DisplayName.ToString() + propertyChange.NewValue;
drNewRow["Time"] = propertyChange.EventTime.ToString("dd/MM/yyyy");
dt.Rows.Add(drNewRow);
}
}
else if (userProfileChange is UserProfileMultiValueChange)
{
UserProfileMultiValueChange propertyChange = (UserProfileMultiValueChange)userProfileChange;
if (!string.IsNullOrEmpty(Convert.ToString(propertyChange.ChangedValue)))
{
drNewRow["UserName"] = propertyChange.ChangedProfile.DisplayName;
drNewRow["Body"] = "updated" + propertyChange.ProfileProperty.DisplayName + propertyChange.ChangedValue;
drNewRow["Time"] = propertyChange.EventTime.ToString("dd/MM/yyyy");
dt.Rows.Add(drNewRow);
}
}
else if (userProfileChange is UserProfileWebLogChange)
{
UserProfileWebLogChange listChange = (UserProfileWebLogChange)userProfileChange;
}
}
}
return dt;
}
}
catch (Exception ex)
{
////logging
}
}
We will not get the Result , as we get in Newsfeed of MySite.Writing this post to let you know we have this approach also.
Remarks: I am trying to get the Colleague Picture also and bind to datatable , but i didn't get that.
The final Look
Thank you.
0 comments:
Post a Comment