Tuesday, January 3, 2012

Insertion into a SharePoint List

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 SharePoint2010Test;
using InsertSampleService;
using System.Xml;
public partial class SharePoint_2010_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string strInsertCommand = string.Empty;
        strInsertCommand = "<Method ID='1' Cmd='New'><Field Name='Title'>" + txtUserName.Text + "</Field><Field Name='Test'>" + txtPassword.Text + "</Field></Method>";
        InsertSampleService.Lists objLogin = new InsertSampleService.Lists();
        objLogin.UseDefaultCredentials=true;
        objLogin.Url = "http://agmsm:9999/sites/Venkat/_vti_bin/Lists.asmx";
        string strListName = "Test";
        XmlDocument xmlDoc = new System.Xml.XmlDocument();

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

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

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

        elBatch.InnerXml = strInsertCommand;

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

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

No comments:

Post a Comment