Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

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.

share|improve this answer
add comment

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?

share|improve this answer
    
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 Nov 26 '10 at 7:25
    
Try to pass the list name and not the list GUID, like: listService.UpdateListItems("Test", batchElement); –  Vivek Nov 26 '10 at 8:05
    
Changed the line to: listService.UpdateListItems("Test", batchElement);, no change –  beuy Nov 26 '10 at 8:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.