Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

2 Answers

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

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.

share|improve this answer
add comment

You can try this power shell script

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

#Load the SharePoint assemblies
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server");
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles");

#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
$count=0;

#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; 

    $oUser.Commit();
} 

#Dispose of site object
$site.Dispose();
share|improve this answer
add comment

Your Answer

 
discard

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.