SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

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"))



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!

share|improve this question

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;
            foreach (var g in collGroup)
share|improve this answer
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 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.