views:

762

answers:

3

In sharepoint when trying to update a list I am getting the error:

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

The Caml that is being created is:

<Batch PreCalc='TRUE' OnError='Continue'>
    <Method ID='1' Cmd='Update'>
        <Field Name='ID'>4</Field>
        <Field Name='Flagged'>False</Field>
     </Method>
</Batch>

When I run the Caml from U2U it works fine and the field updates. When I debug my code in VS I get the error above.

The code creating and calling the Batch is below:

var ws = new com.freud.intranet.lists.Lists {
  Url = WebServiceHelper.wsContactsList,
  Credentials = WebServiceHelper.AdminCredentials
};
var batch = "<Batch PreCalc='TRUE' OnError='Continue'><Method ID='1' cmd='Update'><Field Name='ID'>" + contactID
            + "</Field><Field Name='Flagged'>" + flag + "</Field></Method></Batch>";
var document = new XmlDocument();
var stringReader = new StringReader(batch);
var xmlReader = XmlReader.Create(stringReader);
var node = document.ReadNode(xmlReader);
ws.UpdateListItems("Master Contact Joining Table", node);

Why would the caml work in U2U and not in VS?

From Googling the problem could be because I am not using the intrnal names however it does run in U2U which is why I am confused.

A: 

I was using the wrong List in the code hence the error.

Rupert
A: 

The trick to working with a List is to get the Web Service Location correct, the URL in the referenced web Service set to the correct location, and use the names of the fields as they are defined in the List.

    private void ReadTaskandAddtask()
    {
        try
        {
            tcfifsharepoint.Lists listServiceBase = new tcfifsharepoint.Lists();

            // SharePoint Web Serices require authentication
            listServiceBase.Credentials = System.Net.CredentialCache.DefaultCredentials;
            listServiceBase.Url = "http://SPServer/Site/_vti_Bin/lists.asmx";

            String newIssueTitle = "Programmatically added issue 3";

            String listGUID = "FC519894-509A-4B66-861E-2813DDE14F46";
            String activeItemViewGUID = "C93FFC02-368B-4D06-A8AE-3A3BA52F4F0C";
             listGUID = "{FC519894-509A-4B66-861E-2813DDE14F46}";
             activeItemViewGUID = "{DCF35B63-F85C-463B-B1A1-716B4CF705C5}";

            // first check if item is already in the list
            XmlNode activeItemData = listServiceBase.GetListItems(listGUID, activeItemViewGUID, null, null, "", null, "");
            if (!activeItemData.InnerXml.Contains(newIssueTitle))
            {
                //*********************This is Working *********************************
                StringBuilder sb_method = new StringBuilder();
                sb_method.Append("<Method ID=\"1\" Cmd=\"New\">");
                sb_method.Append("<Field Name=\"Title\">Some Title 14</Field>");
                sb_method.Append("<Field Name=\"AssignedTo\">Name to assign</Field>");
                sb_method.Append("<Field Name=\"Status\">In Progress</Field>");
                sb_method.Append("<Field Name=\"Priority\">(3) Low</Field>");
                sb_method.Append("<Field Name=\"DueDate\">");
                sb_method.Append(DateTime.Parse(DateTime.Now.ToString()).ToString("yyyy-MM-ddTHH:mm:ssZ"));

                sb_method.Append("</Field>");
                sb_method.Append("<Field Name=\"PercentComplete\">.34</Field>");
                sb_method.Append("<Field Name=\"Body\">Something entered into the description field.</Field>");
                sb_method.Append("<Field Name=\"Author\">Your Author</Field>");
                sb_method.Append("<Field Name=\"Editor\">This is Modified By</Field>");
                sb_method.Append("</Method>");

                XmlDocument x_doc = new XmlDocument();

                XmlElement xe_batch = x_doc.CreateElement("Batch");
                xe_batch.SetAttribute("OnError", "Return");
                xe_batch.InnerXml = sb_method.ToString();

                XmlNode xn_return = listServiceBase.UpdateListItems("Task List Name", xe_batch);
        }
        catch (Exception e)
        {
            string sMessage = e.Message;

        }
    }

You can see the internal names used for the list items(Columns) in the SharePoint list by selecting the "Settings" pull down and selecting the "List Settings" Item. Once in the List Settings click on a column and then look at the URL to see the "Field=Name". That is the name you need to be using when you create your fields.

Rich
A: 

Also, you can try opening up SharePoint Designer and taking a peek at any given list form or view.

If you hunt around a little while you will find the List GUID, View GUID, and following that all of the list columns. Looking in SPD is particularly useful when retrieving list items using GetListItems and you need to parse the XML using "ows_" + ColumnName.