Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

How to delete a user from Sharepoint 2010 using client object model

$
0
0

How to delete a user from Sharepoint 2010 using client object model.

My code is as below:

ClientContex ctx =newClientContext(http://contoso.com);

       
Webweb = ctx.Web;

Listolist = ctx.Web.SiteUserInfoList;

ctx.Load(web);

ctx.ExecuteQuery();

           
           

CamlQuerycamlQry =newCamlQuery();

            camlQry.ViewXml =

@"<View>

                                    <Query>

                                        <Where>

                                           <BeginsWith>

                                               <FieldRef Name='Name'/>

                                               <Value Type='Text'>DomainName\UserName</Value>

                                           </BeginsWith>

                                        </Where>

                                    </Query>

                                </View>"

;

           

ListItemCollectionlist  Items = olist.GetItems(camlQry);

            ctx.Load(olist);

            ctx.Load(listItems);

            ctx.ExecuteQuery();

           

         

foreach(ListItemiteminlistItems)

           

            {

        ctx.Load(item);         

     ctx.ExecuteQuery();

             

                item.DeleteObject();

               ctx.ExecuteQuery();

}

I get the error as Cannot complete this action at the last line. i.e ctx.ExecuteQuery(). I found in the net and as such it says that it might be because of caml query not declared properly. I even checked the caml query and there is no problem in it? Can anyone help.                   

        



Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>