Question

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.

Cheers,

Phil

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.

Was it helpful?

Solution

Using .NET reflector on the ActivityManager assembly I was able to conclude that Microsoft disallows these settings from being changed by anyone except for the user who owns the account. In the case above, I was attempting to run the code via console command while logged in as the farm administrator. Because the farm account != the user's account for which the settings apply, Microsoft disallows modification of the settings.

We were able to work around this by having the user run this code (in the background) when they first log into their MySite.

OTHER TIPS

If you add the application pool owner to the group which owns the User Profile Service, you can also get around the permission issue. The code is run from the app pool owner but that person must be the UPS owner because using the Activity Manager requires it. Just another perk of working with MS products!

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top