SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

you may want to check "Using Activity Feeds with Object Model" topic under SharePoint SDK:

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 ( on how to modify 'Activities I'm following' preferences.

share|improve this answer

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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.