Tuesday, January 3, 2012

Creating a SubFolder inside a 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 MyService;
using System.Xml;
public partial class Default16 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        MyService.Lists listProxy = new MyService.Lists();

        //string xmlconst = "<Method ID='1' Cmd='New'><Field Name='FSObjType'>0</Field><Field Name='BaseName'>http://agmsm:9999/sites/Venkat/Sample/Lists/MyList/TestFolder2/Test001/</Field><Field Name='Title'>"+txtCreateSubFolder.Text+"</Field></Method>";
        string str = "TestFolder2/" + txtCreateSubFolder.Text;
        if (str.ToString().Contains("&"))
        {

            //str = str.Replace("&", "/g");

        }
        string xmlconst = "<Method ID='1' Cmd='New'><Field Name='FSObjType'>1</Field><Field Name='BaseName'>" + str + "</Field></Method>";
       
        
       

        listProxy.Url = "http://agmsm:9999/sites/Venkat/Sample/_vti_bin/lists.asmx";
        listProxy.UseDefaultCredentials = true;


        string strListName = "MyList";
        XmlDocument xmlDoc = new System.Xml.XmlDocument();

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

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

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

        
        elBatch.InnerXml = xmlconst;

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

        string result = ndReturn.OuterXml.ToString();
        Page.RegisterClientScriptBlock("alert", "<Script language='JavaScript'>alert('Folder Created Successful');</Script>");
        txtCreateSubFolder.Text = "";
    }
}

No comments:

Post a Comment