How to add a new item in a sharepoint list using web services in C sharp
<p>I'm trying to add a new item to a sharepoint list from a winform application in c# using web services. As only result, I'm getting the useless exception "Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown."</p>

<p>I have a web reference named WebSrvRef to <a href="http://server/site/subsite/_vti_bin/Lists.asmx" rel="nofollow">http://server/site/subsite/_vti_bin/Lists.asmx</a></p>

<p>And this code:</p>

<pre><code>        XmlDocument xmlDoc;
        XmlElement elBatch;
        XmlNode ndReturn;
        string[] sValues;
        string sListGUID;
        string sViewGUID;

        if (lstResults.Items.Count &lt; 1)
        {
            MessageBox.Show("Unable to Add To SharePoint\n" +
                "No test file processed. The list is blank.", 
                "Add To SharePoint", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            return;
        }

        WebSrvRef.Lists listService = new WebSrvRef.Lists();
        sViewGUID = "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}"; // Test List View GUID
        sListGUID = "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}"; // Test List GUID

        listService.Credentials= System.Net.CredentialCache.DefaultCredentials;

        frmAddToSharePoint dlgAddSharePoint = new frmAddToSharePoint();
        if (dlgAddSharePoint.ShowDialog() == DialogResult.Cancel)
        {
            dlgAddSharePoint.Dispose();
            listService.Dispose();
            return;
        }

        sValues = dlgAddSharePoint.Tag.ToString().Split('~');
        dlgAddSharePoint.Dispose();

        string strBatch = "&lt;Method ID='1' Cmd='New'&gt;" +
            "&lt;Field Name='Client#'&gt;" + sValues[0] + "&lt;/Field&gt;" +
            "&lt;Field Name='Company'&gt;" + sValues[1] + "&lt;/Field&gt;" +
            "&lt;Field Name='Contact Name'&gt;" + sValues[2] + "&lt;/Field&gt;" +
            "&lt;Field Name='Phone Number'&gt;" + sValues[3] + "&lt;/Field&gt;" +
            "&lt;Field Name='Brand'&gt;" + sValues[4] + "&lt;/Field&gt;" +
            "&lt;Field Name='Model'&gt;" + sValues[5] + "&lt;/Field&gt;" +
            "&lt;Field Name='DPI'&gt;" + sValues[6] + "&lt;/Field&gt;" +
            "&lt;Field Name='Color'&gt;" + sValues[7] + "&lt;/Field&gt;" +
            "&lt;Field Name='Compression'&gt;" + sValues[8] + "&lt;/Field&gt;" +
            "&lt;Field Name='Value % 1'&gt;" + (((float)lstResults.Groups["Value 1"].Tag)*100).ToString("##0.00") + "&lt;/Field&gt;" +
            "&lt;Field Name='Value % 2'&gt;" + (((float)lstResults.Groups["Value 2"].Tag)*100).ToString("##0.00") + "&lt;/Field&gt;" +
            "&lt;Field Name='Value % 3'&gt;" + (((float)lstResults.Groups["Value 3"].Tag)*100).ToString("##0.00") + "&lt;/Field&gt;" +
            "&lt;Field Name='Value % 4'&gt;" + (((float)lstResults.Groups["Value 4"].Tag)*100).ToString("##0.00") + "&lt;/Field&gt;" +
            "&lt;Field Name='Value % 5'&gt;" + (((float)lstResults.Groups["Value 5"].Tag)*100).ToString("##0.00") + "&lt;/Field&gt;" +
            "&lt;Field Name='Comments'&gt;&lt;/Field&gt;" +
            "&lt;Field Name='Overall'&gt;" + (fTotalScore*100).ToString("##0.00") + "&lt;/Field&gt;" +
            "&lt;Field Name='Average'&gt;" + (fTotalAvg * 100).ToString("##0.00") + "&lt;/Field&gt;" +
            "&lt;Field Name='Transfered'&gt;" + sValues[9] + "&lt;/Field&gt;" +
            "&lt;Field Name='Notes'&gt;" + sValues[10] + "&lt;/Field&gt;" +
            "&lt;Field Name='Resolved'&gt;" + sValues[11] + "&lt;/Field&gt;" +
            "&lt;/Method&gt;";

        try
        {
            xmlDoc = new System.Xml.XmlDocument();
            elBatch = xmlDoc.CreateElement("Batch");

            elBatch.SetAttribute("OnError", "Continue");
            elBatch.SetAttribute("ListVersion", "1");
            elBatch.SetAttribute("ViewName", sViewGUID);

            strBatch = strBatch.Replace("&amp;", "&amp;amp;");
            elBatch.InnerXml = strBatch;

            ndReturn = listService.UpdateListItems(sListGUID, elBatch);

            MessageBox.Show(ndReturn.OuterXml);
            listService.Dispose();                
        }
        catch(Exception Ex)
        {
            MessageBox.Show(Ex.Message +
                "\n\nSource\n" + Ex.Source +
                "\n\nTargetSite\n" + Ex.TargetSite +
                "\n\nStackTrace\n" + Ex.StackTrace, 
                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            listService.Dispose();
        }
</code></pre>

<p>What am I doing wrong? What am I missing?
Please help!!</p>

<p>Frank</p>
