Hello and thanks for reading. I've been working with the out-of-box SharePoint 2010 News Feed portion of My Sites, and I am planning to deploy it to many users.
I am building a console application which will iterate through all of the my sites currently in the system and un-check one of the "Activities I am following' for each user. I have used the example provided at this link (MSDN) to come up with the following code:
Public Class ChangeActivity 'Reference: http://msdn.microsoft.com/en-us/library/ff426883.aspx' Public Shared Sub ChangeActivityProperties() Using siteCol As New SPSite((My.Application.CommandLineArgs(0))) Dim context As SPServiceContext = SPServiceContext.GetContext(siteCol) Dim profileManager As New UserProfileManager(context) Dim profile As UserProfile = profileManager.GetUserProfile("THEDOMAIN\username") Dim activityMan As ActivityManager = New ActivityManager(profile, context) 'Create an instance of a list of ActivityPreferencePerType objects.' Dim activityPrefsPerType As New List(Of ActivityPreferencePerType)(activityMan.ActivityTypes.Count) 'Get each ActivityType stored in ActivityManager, and for testing purposes, set each ActivityType as a true ActivityPreference.' For Each activityType As ActivityType In activityMan.ActivityTypes If activityType.ActivityTypeNameLocStringName = "ActivityFeed_DLMembershipChange_Type_Display" Then Dim newPref As New ActivityPreferencePerType() newPref.ActivityType = activityType newPref.IsSet = False activityPrefsPerType.Add(newPref) Console.WriteLine(activityType.ActivityTypeName + " " + activityType.ActivityTypeId.ToString()) End If Next 'Set activity preferences for the user.' activityMan.ActivityPreferences.SetActivityPreferencesPerType(activityPrefsPerType) Console.ReadKey(True) End Using End Sub End Class
This code compiles and executes without error, but appears to have no affect on the Activities that the user is subscribed to for their news feed. Anyone else had a similar issue? It seems like it would be a common enough problem if one were to take a serious attempt at implementing My Sites in SharePoint 2010.
Thanks for your time, and your help in advance.
UPDATE Doing some powershell sleuthing it appears that this might be a problem with my ActivityManager object. I instantiate the ActivityManager object as above, passing in the UserProfile for the user "THEDOMAIN\username". When I inspect the object after creating it, it appears that the "CurrentUserName" is set to the service account (which happens to be the account I am logged into on the machine). MSDN describes the current user member of ActivityManager as:
"Gets a string representing the current user’s name."
The properties in the ActivityManager also appear to be configured like the Service Account's settings, rather than the "THEDOMAIN\username" user.