Inserting list item in SP 2013 using ASP.NET

Hi,

I have written below code to add an item programaticaly from ASP.NET

            RebateService.Lists listService = new RebateService.Lists();
            //listService.Credentials = System.Net.CredentialCache.DefaultCredentials;

            System.Net.NetworkCredential userDefined = new System.Net.NetworkCredential(                                                  );

            listService.Credentials = userDefined;

            listService.Url = "http://domaindev/Rebate/_vti_bin/lists.asmx";

            /*Get Name attribute values (GUIDs) for list and view. */
            System.Xml.XmlNode ndListView = listService.GetListAndView("Rebate Test", "");
            string strListID = ndListView.ChildNodes[0].Attributes["Name"].Value;
            string strViewID = ndListView.ChildNodes[1].Attributes["Name"].Value;

            /*Create an XmlDocument object and construct a Batch element and its
            attributes. Note that an empty ViewName parameter causes the method to use the default view. */
            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);

            /*Specify methods for the batch post using CAML. To update or delete, 
            specify the ID of the item, and to update or add, specify 
            the value to place in the specified column.*/
            batchElement.InnerXml = "<Method ID='1' Cmd='New'>" +
               "<Field Name='Title'>6</Field>" +
               "<Field Name='Rebate Name'>Modified sixth item</Field></Method>";

            /*Update list items. This example uses the list GUID, which is recommended, 
            but the list display name will also work.*/
            try
            {
                listService.UpdateListItems("Rebate Test", batchElement);
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
            }

While running the code, it is not throwing any error but while checking in sharpoint it is not showing newly added value.

Please help,

July 23rd, 2015 3:08am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics