is it possible to programatically select/deselect activities I am following on the news feed preferences page under MySites? I want to be able switch on/off notifications for both custom events and those provided by Sharepoint 2010 out-of-the-box.


you may want to check "Using Activity Feeds with Object Model" topic under SharePoint SDK: http://msdn.microsoft.com/en-us/library/ff426881.aspx

Below you can find example that will list current user 'Activities I'm following' settings.

string currentSite = "http://URL goes here";
using (SPSite aSite = new SPSite(currentSite))
    SPServiceContext currentContext = SPServiceContext.GetContext(aSite);
    UserProfileManager userProfMan = new UserProfileManager(currentContext);
    string userName = Environment.UserDomainName + "\\" + Environment.UserName;
    UserProfile currentUser = userProfMan.GetUserProfile(userName);
    ActivityManager activityMan = new ActivityManager(currentUser, currentContext);
    foreach (ActivityType activityType in activityMan.ActivityTypes)
         Console.WriteLine(activityType.ActivityTypeName + " " + activityType.ActivityTypeId + " " 
         + (activityMan.ActivityPreferences[activityType.ActivityTypeId] != null ? "true" : "false"));

Look at the 'How to: Get Events for Users' code sample (http://msdn.microsoft.com/en-us/library/ff426883(v=office.14).aspx) on how to modify 'Activities I'm following' preferences.


You can try this power shell script

#Load the SharePoint snap-in
Add-PsSnapin Microsoft.SharePoint.PowerShell;

#Load the SharePoint assemblies

#Specify the MySite URL
$MySiteUrl = "http://santosh-pc:39242/";

#Get the server context for the profile manager
$site = Get-SPSite $MySiteUrl;
$ServerContext = Get-SPServiceContext $site;
$UPManager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServerContext);

#Count variables
$ucount = 0;

$enumProfiles = $UPManager.GetEnumerator();
"Total User Profiles available:" + $UPManager.Count

#Loop through the profile entries and update the property
#Recieve Instant Notifications - NGAllowMetaEmail (bool)
#24 Hour Digest Email - NGReceiveDigestEmail (bool)
#RSS NewsFeed Email - NGAllowRssEmail (bool)
#SharePoint Notification emails - SPS-EmailOptin (int)
#This field has 3 values one for each email type

foreach ($oUser in $enumProfiles)
    $count = $count + 1;
    $u = $oUser.Item("Accountname");
    Write-Output "($count):  Setting values for $u";

    $oUser["NGAllowMetaEmail"].Value = $false;
    $oUser["NGReceiveDigestEmail"].Value = $false;
    $oUser["NGAllowRssEmail"].Value = $false;
    $oUser["SPS-EmailOptin"].Value = 111; 


#Dispose of site object

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.