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 an Item from a list using the following code:

using System;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;

namespace Microsoft.SDK.SharePointServices.Samples
{
class DeleteListItem
{
    static void Main()
    {   
        string siteUrl = "http://MyServer/sites/MySiteCollection";

        ClientContext clientContext = new ClientContext(siteUrl);
        SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");
        ListItem oListItem = oList.GetItemById(2);

        oListItem.DeleteObject();

        clientContext.ExecuteQuery(); 
    }
}

}

for any item Id I try to delete, I always get the same message :

Item does not exist. It may have been deleted by another user.

share|improve this question
1  
are you sure that you have access to the item? –  Alexander Mar 16 '12 at 14:51
    
With the same code trying to add or get a item I can access to. –  Bruno Ferreira Mar 16 '12 at 16:40
    
Your code works perfectly for me. There must be a simple mismatch some place. –  Robert Kaucher Mar 16 '12 at 19:23
    
Just something I noticed: Why have you declared Microsoft.SharePoint.Client twice in the usings section? –  Vardhaman Deshpande Jul 31 '12 at 13:08
add comment

1 Answer

Try something like:

string siteUrl = "http://MyServer/sites/MySiteCollection";

ClientContext clientContext = new ClientContext(siteUrl);
SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");

clientContext.Load(oList);
clientContext.ExecuteQuery()

ListItem oListItem = oList.GetItemById(2);

clientContext.Load(oListItem);
clientContext.ExecuteQuery();

oListItem.DeleteObject();

clientContext.ExecuteQuery();   

This worked for me...

share|improve this answer
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.