How to delete objects in Sharepoint with C#?

Viewed 27

I have a list generated by SSIS conditional split. I tried to delete in sharepoint site from each item from the list using C# However, I execute the deleteobject() ; and the context.ExecuteQuery(); it catch the following error :

[Move SP SOQ [297]] Error: Error on ExecuteQuery SP Insert.Item does not exist.

The page you selected contains an item that does not exist. It may have been deleted by another user.

        //Authentification au site SP page prncipale
        string url = Variables.ListURLdelete;
        ClientContext context = new ClientContext(url);
        context.AuthenticationMode = ClientAuthenticationMode.Default;
        context.Credentials = new NetworkCredential(Variables.WebServiceServerUserName, Variables.WebServiceServerPassword);

        Web web = context.Web;
      
        List SOQList = context.Web.Lists.GetByTitle("SOQ");
        var item = SOQList.AddItem(new ListItemCreationInformation());
        if (Row.SOQENDDate >= 10)
        {

            if (!Row.Assignment_IsNull)
            {
                item["SOQAssignmentCode"] = Row.Assignment;
            }
            //if (!Row.AssignmentLabel_IsNull)
            //{
            //    item["SOQAssignmentStatus"] = Row.AssignmentLabel;
            //}
            //if (!Row.SOQTitle_IsNull)
            //{
            //    item["Title"] = Row.SOQTitle;
            //}
            //Insertion dans SP
            // https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ee539976(v=office.14)
            try
            {
                Console.WriteLine(item);
                item.DeleteObject();
            }
            catch (Exception d)
            {
                ComponentMetaData.FireError(0, "", "Error on Update Items SP Insert." + d.Message, "", 0, out vbool);
            }
            try
            {
                context.ExecuteQuery();
            }
            catch (Exception d)
            {
                ComponentMetaData.FireError(0, "", "Error on ExecuteQuery SP Insert." + d.Message, "", 0, out vbool);
            }
        }

    }

Could it be that the error is on the List SOQList = context.Web.Lists.GetByTitle("SOQ"); ?

0 Answers
Related