Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Monday, November 28, 2011

Inserting a listitem inside a subfolder in a sharepoint list 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 System.Xml;
using MySite_Dat;
using Microsoft.SharePoint;
public partial class Default17 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnSave_Click(object sender, EventArgs e)
{
string strInsertCommand = string.Empty;
string strSelectedFolder = string.Empty;
string strListName = "MyList";
strSelectedFolder = "http://vlnrm:100/Sample/Lists/MyList/TestFolder2/" + DropDownList1.SelectedItem.Value;
strInsertCommand = "" + txtTitle.Text + "";
MySite_Dat.Lists objLogin = new MySite_Dat.Lists();
objLogin.UseDefaultCredentials=true;
objLogin.Url = "http://http://vlnrm:100/Sample/_vti_bin/Lists.asmx";
XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");
elBatch.SetAttribute("RootFolder", strSelectedFolder);
elBatch.SetAttribute("OnError", "Continue");
elBatch.SetAttribute("ListVersion", "1");
elBatch.InnerXml = strInsertCommand;
try
{
XmlNode ndReturn = objLogin.UpdateListItems(strListName, elBatch);
string result = ndReturn.OuterXml.ToString();
}
catch (Exception ex)
{
this.Controls.Add(new LiteralControl(ex.ToString()));
}
txtTitle.Text = "";
}
}

No comments:

Post a Comment