Tuesday, January 3, 2012

Updating a Record basedon 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 Default8 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        string strUpdateCommand = string.Empty;
        strUpdateCommand = "<Method ID='1' Cmd='Update'><Field Name='ID'>" + ddlItemID.SelectedItem.Value +"</Field><Field Name='Title'>" + txtUserName.Text + "</Field><Field Name='Password'>" + txtPassWord.Text + "</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 = strUpdateCommand;

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

        string result = ndReturn.OuterXml.ToString();
        txtUserName.Text = "";
        txtPassWord.Text = "";
        txtUserName.Focus();
    }
}

No comments:

Post a Comment