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 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.

share|improve this question
    
What type of field is tt_contentid? –  Robert Kaucher Mar 20 '12 at 15:30
    
And is tt_contentid the internal name of the field? –  Per Jakobsen Mar 20 '12 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 –  Per Jakobsen Mar 20 '12 at 17:02

2 Answers 2

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?

share|improve this answer

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

share|improve this answer

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.