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'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!

share|improve this question
add comment

1 Answer 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);
            }
        }
    }
}
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); –  Bruno Ferreira 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. –  Bruno Ferreira 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
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.