0

I'm trying to delete groups and Sites from Sharepoint using COM.

 Ex: Listitem i = ........;     i.DeleteObject(); 

Now, in my code , I'm using this snippet:

   foreach (Group grpsSP in collGroup)
            {

                if (grpsSP.Title.Equals((grup.PK_Site).ToString() + "-1"))
                {

                    grpsSP.
                    clientContext.ExecuteQuery();

                    clientContext.ExecuteQuery();
                }
            }

but on the grpsSP object I don't find any reference to a Delete() method. Has anyone any idea about witch classes should I invoke to get the delete method? thanks!

1

You need GroupCollection.Remove and Web.DeleteObject

Here is an example of looping through all groups:

using System;
using Microsoft.SharePoint.Client;

namespace Microsoft.SDK.SharePointFoundation.Samples
{
    class GroupCollectionExample
    {
        static void Main()
        {
            string siteUrl = "http://sharepoint";

            ClientContext clientContext = new ClientContext(siteUrl);
            Web site = clientContext.Web;
            GroupCollection collGroup = site.SiteGroups;
            clientContext.Load(collGroup);
            clientContext.ExecuteQuery();
            Console.WriteLine(collGroup.Count);
            foreach (var g in collGroup)
            {
                Console.WriteLine(g.Title);
            }
        }
    }
}
  • thanks, do you knows what ca I do to identify a group inside So context? Every group has a name like "group-1, group-2". But I need something like an ID. I'd like to use this code. ButI think I need ID. Group testingVisitorsGroup = web.SiteGroups.GetById(7); – hello B May 24 '12 at 13:57
  • See example added – Per Jakobsen May 24 '12 at 14:10
  • mmm. I don't know but it seems tha something is wrong. When I run the code it gives me the exception : The remote name could not be resolved. – hello B May 24 '12 at 14:38
  • Did you change the siteUrl? And in your sample you just need collGroup.Remove(grpsSP); – Per Jakobsen May 24 '12 at 15:31

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.