0

The following code compiles with no errors:

        ListsWebServices.Lists listService = new ListsWebServices.Lists();
        listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
        listService.Url = "http://toplevel/OC/coldrooms/_vti_bin/lists.asmx";
        System.Xml.XmlNode ndListView = listService.GetListAndView("Test", "");
        string strListID = ndListView.ChildNodes[0].Attributes["Name"].Value;
        string strViewID = ndListView.ChildNodes[1].Attributes["Name"].Value;
        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
        System.Xml.XmlElement batchElement = doc.CreateElement("Batch");
        batchElement.SetAttribute("OnError", "Continue");
        batchElement.SetAttribute("ListVersion", "1");
        batchElement.SetAttribute("ViewName", strViewID);
        batchElement.InnerXml = "<Method ID='1' Cmd='New'>" +
        "<Field Name='ID'>New</Field>" +
        "<Field Name='User'>MR ANDERSON</Field>" +
        "</Method>";
        try
        {
            listService.UpdateListItems(strListID, batchElement);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

But does not add any new item to the List, I have confirmed that it gets the right GUID's by opening the list in sharepoint designer and cross referencing. Any advice as to where I am going wrong would be greatly appreciated.

2 Answers 2

2

I found the answer, turns out that Internal field names can and often are separate from External Field names. In short the created name "User" was not in fact called "User", it was something else.

1

Try passing "" as the view guid like: batchElement.SetAttribute("ViewName", "");

Also check that : 1. what is the type of the USER filed? 2. Are there any mandatory fields in the list?

3
  • Hi there, User field is of "Single line of text" and is Mandatory There are no other created fields. I've also changed the ViewName Attribute to "", however am getting the same result.
    – beuy
    Commented Nov 26, 2010 at 7:25
  • Try to pass the list name and not the list GUID, like: listService.UpdateListItems("Test", batchElement);
    – Vivek
    Commented Nov 26, 2010 at 8:05
  • Changed the line to: listService.UpdateListItems("Test", batchElement);, no change
    – beuy
    Commented Nov 26, 2010 at 8:43

Your Answer

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