0

I'm trying to delete but the code seems that can't find the Item field :

 try
        {
            using (ClientContext context = new ClientContext("http://to0wss2k10rey03/sites/ReplyCorp"))
            {

                if (WindowsIdentity.GetCurrent().IsAuthenticated)
                {
                    var currentCredential = System.Net.CredentialCache.DefaultCredentials;
                    context.Credentials = currentCredential;

                    try
                    {
                        SP.List oList = context.Web.Lists.GetByTitle("ContentIndex");
                        CamlQuery camlQuery = new CamlQuery();
                        camlQuery.ViewXml = @"<View>
                        <Query>
                          <Where>
                            <Eq>
                              <FieldRef Name='tt_contentid'/>
                              <Value Type='Text'>ContentIndex_test</Value>
                            </Eq>
                          </Where>
                        </Query>                            
                      </View>";
                        ListItemCollection collListItem = oList.GetItems(camlQuery);

                        context.Load(collListItem);

                        context.ExecuteQuery();


                        int id = COUNT;
                        foreach (ListItem oListItem in collListItem)
                        {
                            if (oListItem["tt_contentid"].Equals(id))
                            {
                                oListItem.DeleteObject();

                            }
                        }
                       oList.Update();
                    }
                    catch
                    {
                        throw new ArgumentException("Can't find Item with this ID " /*+ updateContentObj.contentId, "tt_contentid"*/);
                    }

The code always go to the exception: "can't find Item whit ID" and give me the following error message:

One or more field types are not installed properly. Go to the list settings page to delete these fields.

3
  • What type of field is tt_contentid? Mar 20, 2012 at 15:30
  • And is tt_contentid the internal name of the field? Mar 20, 2012 at 15:53
  • Your code also looks wierd in that you have a query to find items where tt_contentid == "ContentIndex_test" and the you check the same value to be equal to an int Mar 20, 2012 at 17:02

2 Answers 2

1

Try this...

context.Load(collListItem, li => li.Include(f => f["tt_contentid"]));

If you do not specifically request that a field be loaded you will get a

The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.

exception.

Sorry, I did not get to see your edit before submitting. Are you sure that field name is same as the field's internal name?

0

One or more field types are not installed properly. Go to the list settings page to delete these fields.

This error occurs when there are some corrupted fields present. Did you create any custom fields in the list recently? If yes, delete and re-create them. That should solve this problem.

In your code, you have written that int id = COUNT;. What is COUNT? Is it come constant declared somewhere above in your code?

Also, you don't need to call the oList.Update(); after you delete the list item. You need to call the context.ExecuteQuery(); again.

I have tried to simplify your code. See if it works:

try
{
    using (ClientContext context = new ClientContext("http://to0wss2k10rey03/sites/ReplyCorp"))
    {
        if (WindowsIdentity.GetCurrent().IsAuthenticated)
        {
            var currentCredential = System.Net.CredentialCache.DefaultCredentials;
            context.Credentials = currentCredential;

            try
            {
                SP.List oList = context.Web.Lists.GetByTitle("ContentIndex");
                CamlQuery camlQuery = new CamlQuery();
                camlQuery.ViewXml = @"<View>
                <Query>
                  <Where>
                    <Eq>
                      <FieldRef Name='tt_contentid'/>
                      <Value Type='Text'>ContentIndex_test</Value>
                    </Eq>
                  </Where>
                </Query>                            
              </View>";

                ListItemCollection collListItem = oList.GetItems(camlQuery);

                context.Load(collListItem);

                context.ExecuteQuery();


                int id = COUNT;
                foreach (ListItem oListItem in collListItem)
                {
                    if (oListItem["tt_contentid"].ToString().Equals(id))
                    {
                        oListItem.DeleteObject();

                    }
                }

               context.ExecuteQuery();
            }
        }   
    }
}
catch
{
    throw new ArgumentException("Can't find Item with this ID");
}

Also, this link should help you in the most common programming tasks with the Managed Client Object Model:

http://msdn.microsoft.com/en-us/library/ee537013.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.