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

I have a site collection that have a teamsite, when a normal user posts something in the microfeed webpart the site collection administrator/site owner of the teamsite cant remove the post that the user member did. But the user that created the post can remove it..

Did Microsoft even think about that? What if a user write something racist...

share|improve this question
add comment

2 Answers 2

If you want to have a specific user be able to delete users posts then you will need to give them Manage Social Data permissions on your User Profile Service application.

Go to Service Applications - highlight the user profile service and click Administrators from the ribbon. Add a user account and select Manage Social Data from the permissions list.

The user will then be able to click the "..." next to any post and either Lock the conversation or delete the post.

share|improve this answer
    
Thanks Richard but what if the site owner should be able to lock and delete? –  Rohander Mar 28 '13 at 7:36
    
Is there anyway to make sure that all site owners get the social data permission? –  Rohander Mar 28 '13 at 7:49
    
Also this makes the user be able to delete and lock all posts from all teamsites and socialsites, thats not good –  Rohander Mar 28 '13 at 9:07
add comment

Code example: Delete posts and replies from the social feed by using the SharePoint 2013 .NET client object model

The following code example deletes a post or a reply from the current user's personal feed. It shows how to:

• Get the Personal feed type for the current user by using the GetFeed method.

• Iterate through the threads in the feed to get information about the root post and replies.

• Delete a root post, reply, or thread by using the DeletePost method (deleting a root post deletes the whole thread).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Social;

namespace SocialFeedCSOM
{
    class Program
    {
        static void Main(string[] args)
        {

            // Replace the following placeholder value with the target SharePoint server.
            const string serverUrl = "http://serverName/";

            // Get the client context.
            ClientContext clientContext = new ClientContext(serverUrl);

            // Get the SocialFeedManager instance.
            SocialFeedManager feedManager = new SocialFeedManager(clientContext);

            Console.WriteLine("\nCurrent user's personal feed:");

            // Set the parameters for the feed content that you want to retrieve.
            SocialFeedOptions feedOptions = new SocialFeedOptions();

            // Get the target owner's feed (posts and activities) and
            // then run the request on the server.
            ClientResult<SocialFeed> feed = feedManager.GetFeed(SocialFeedType.Personal, feedOptions);
            clientContext.ExecuteQuery();

            // Create a dictionary to store the Id property of each post and
            // reply. This code example stores the Id so you can select a post
            // or a reply to delete.
            Dictionary<int, string> idDictionary = new Dictionary<int, string>();

            // Iterate through each thread in the feed.
            for (int i = 0; i < feed.Value.Threads.Length; i++)
            {
                SocialThread thread = feed.Value.Threads[i];
                SocialPost rootPost = thread.RootPost;

                // Only keep posts that can be deleted.
                if (rootPost.Attributes.HasFlag(SocialPostAttributes.CanDelete)) 
                {
                    idDictionary.Add(i, rootPost.Id);

                    Console.WriteLine(string.Format("{0}. \"{1}\" has {2} replies.",
                        (i + 1), rootPost.Text, thread.TotalReplyCount));

                    // Get the replies.
                    // If a thread contains more than two replies, the server returns
                    // a thread digest that contains only the two most recent replies.
                    // To get all replies, call SocialFeedManager.GetFullThread.
                    if (thread.TotalReplyCount > 0)
                    {
                        foreach (SocialPost reply in thread.Replies)
                        {

                            // Only keep replies that can be deleted.
                            if (reply.Attributes.HasFlag(SocialPostAttributes.CanDelete)) 
                            {
                                i++;
                                idDictionary.Add(i, reply.Id);

                                SocialActor author = thread.Actors[reply.AuthorIndex];
                                Console.WriteLine(string.Format("\t{0}. {1} replied \"{2}\"",
                                    (i + 1), author.Name, reply.Text));
                            }
                        }
                    }
                }
            }
            Console.Write("\nEnter the number of the post or reply to delete. "
                + "(If you choose a root post, the whole thread is deleted.)");
            string postToDelete = "";
            int postNumber = int.Parse(Console.ReadLine()) - 1;
            idDictionary.TryGetValue(postNumber, out postToDelete);

            // Delete the reply and make the changes on the server.
            ClientResult<SocialThread> result = feedManager.DeletePost(postToDelete);
            clientContext.ExecuteQuery();

            // DeletePost returns digest thread if the deleted post is not the
            // root post. If it is the root post, the whole thread is deleted
            // and DeletePost returns null.
            if (result.Value != null)
            {
                SocialThread threadResult = result.Value;
                Console.WriteLine("\nThe reply was deleted. The thread now has {0} replies.", threadResult.TotalReplyCount);
            }
            else
            {
                Console.WriteLine("\nThe post and thread were deleted.");
            }
            Console.ReadKey(false);
        }
    }
}

http://msdn.microsoft.com/en-gb/library/jj163977.aspx

or

using js

http://msdn.microsoft.com/en-us/library/jj164025.aspx

api to delete posts or get posts for any user

http://msdn.microsoft.com/en-gb/library/jj163237.aspx

I have read that its on the current user but i belive it should work on all users! if it doesnt and only on the current logged in user than thats where impersonation comes to action ;) to get the user your looking for :)

SharePoint -access to path is denied

look at my post in the link above to impersonat a user, when you have the SPSite and SPWeb under the user you can than proceed to delete the post :)

to impersonate you need to get the system token first and make sharepoint think that your that person, anything within the SPSite that your going to impersonate will be under that user and not the current user your using, the method below is getting the system account token with elevated privlages (for anonymous users):

/// <summary>
/// get the system token from the list of users to elevate spsite
/// </summary>
/// <param name="spSite"></param>
/// <returns></returns>
protected static SPUserToken GetSystemToken(SPSite spSite) 
{     
    SPUserToken res = null;     
    bool oldCatchAccessDeniedException = spSite.CatchAccessDeniedException;
    try
    {
        spSite.CatchAccessDeniedException = false;
        res = spSite.SystemAccount.UserToken;
    }
    catch (UnauthorizedAccessException)
    {
        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            using (SPSite elevatedSPSite = new SPSite(spSite.ID))
                res = elevatedSPSite.SystemAccount.UserToken;
            // (***)         
        });
    }
    finally    
    {         
        spSite.CatchAccessDeniedException = oldCatchAccessDeniedException;     
    }     
    return res; 
}

to use this method you would need to do the following:

        SPUserToken sysToken = null;
        using (SPSite spSite = new SPSite(SPContext.Current.Site.ID))
        {
            //get the system token from the method GetSystemToken and passing the spSite that you want to run under
            sysToken = GetSystemToken(spSite);

            using (SPSite impersonatedSite = new SPSite(siteUrl, sysToken))
            {
                //we are impersonating the [@"SHAREPOINT\SYSTEM"] account
                using (SPWeb web = impersonatedSite.OpenWeb())
                {
                     //do your code here as the impersonated account like updating a list
                }
            }
        }

merge the two solutions together and youve got a winner :) , an admin/owner being able to delete any post by an any user within a microfeed. PS make sure that its only visable/accessible for admin/owner lol

share|improve this answer
    
Hey Ali could you join this chat chat.stackexchange.com/rooms/8182/obsivus –  Rohander Apr 3 '13 at 12:31
    
says i need to be logged in even tho i am :( –  ali Sharepoint Apr 3 '13 at 12:34
    
your in now I think –  Rohander Apr 3 '13 at 12:35
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.