I'm writing a method to programmatically follow or unfollow documents in SharePoint 2013. The idea is to call the method providing the path to the document, the user and a bool indicating if we're turning following on or off for the particular document and user.
The problem is that when I call the Follow method (or StopFollowing) on my FollowManager, I get this execption:
SPSocialException was caught
"The operation failed because an internal error occurred. Internal type name: Microsoft.Office.Server.UserProfiles.FollowedContentException. Internal error code: 11."
Here's my code. Everything works fine until the if (follow) clause. The user and document objects are valid, the path exists and is accessible.
private static string FollowOrUnfollowDocument(string absouteEncodedPathDocument, SPUser user, bool follow) { string retval = string.Empty; SPSecurity.RunWithElevatedPrivileges(delegate() { try { SPServiceContext serverContext = SPServiceContext.GetContext(SPContext.Current.Web.Site); UserProfileManager profileManager = new UserProfileManager(serverContext); UserProfile profile = profileManager.GetUserProfile(user.LoginName); if (profile != null) { SPSocialFollowingManager followManager = new SPSocialFollowingManager(profile); SPSocialActorInfo newActor = new SPSocialActorInfo(); Uri serverUri = new Uri(SPContext.Current.Web.Url); Uri relativeUri = new Uri(absouteEncodedPathDocument, UriKind.Absolute); newActor.ContentUri = new Uri(serverUri, relativeUri); newActor.AccountName = user.LoginName; newActor.ActorType = SPSocialActorType.Document; if (follow) followManager.Follow(newActor); else followManager.StopFollowing(newActor); } } catch (Exception ex) { retval = ex.Message; } }); return retval; }
Any ideas? What does internal error 11 mean?