Tuesday, January 3, 2012

Delete a record based on ItemID using SharePoint Default WebService.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PrasadBolla3;
using System.Xml;
public partial class Default9 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        string strDeleteCommand = string.Empty;
        strDeleteCommand = "<Method ID='1' Cmd='Delete'><Field Name='ID'>"+ddlItemID.SelectedItem.Value+"</Field></Method>";
        PrasadBolla3.Lists objLogin = new PrasadBolla3.Lists();
        objLogin.Credentials = new System.Net.NetworkCredential("true_indian9000", "prasad1234", "apptix");
        objLogin.Url = "http://agmsm:9999/_vti_bin/Lists.asmx";
        string strListName = "Login";
        XmlDocument xmlDoc = new System.Xml.XmlDocument();

        System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");

        elBatch.SetAttribute("OnError", "Continue");

        elBatch.SetAttribute("ListVersion", "1");

        elBatch.InnerXml = strDeleteCommand;

        XmlNode ndReturn = objLogin.UpdateListItems(strListName, elBatch);

        string result = ndReturn.OuterXml.ToString();
        Response.Write("Record Deleted");
    }
}

No comments:

Post a Comment