Tuesday, January 3, 2012

Retrieving subsites under the topsite to a spgridview

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 Webs;
using System.Xml;
public partial class Default11 : System.Web.UI.Page
{
    DataSet dset = new DataSet();
    //DataSet dset1 = new DataSet();
    //DataTable dt = new DataTable();   
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           
            Webs.Webs web_Service = new Webs.Webs();
            web_Service.UseDefaultCredentials=true;
            web_Service.Url = "http://agmsm:9999/sites/mnet/venkat/_vti_bin/webs.asmx";
            System.Xml.XmlNode nodeListItems = web_Service.GetWebCollection();
            DataSet ds = getData(nodeListItems);
            DataTable  dt = ds.Tables["Web"];
            GridView1.DataSource = dt;
            GridView1.DataBind();
            Response.Write("<Table>");
            Response.Write("<Tr>");
            Response.Write("<Td>");
            Response.Write("Subsites List");
            Response.Write("</Td>");
            Response.Write("</Tr>");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string strTitle = dt.Rows[i]["Title"].ToString();
                string strUrl = dt.Rows[i]["Url"].ToString();
                Response.Write("<Tr>");
                Response.Write("<Td>");
                Response.Write("<A href='"+strUrl+"'>"+strTitle+"</A>");
                Response.Write("</Td>");
                Response.Write("</Tr>");
            }
            Response.Write("</Table>");
        }
    }
    public DataSet getData(XmlNode xmlnodeinput)
    {
        if (xmlnodeinput != null)
        {
            XmlTextReader xtr = new XmlTextReader(xmlnodeinput.OuterXml, XmlNodeType.Element, null);
            //dataset = new DataSet();
            dset.ReadXml(xtr);
        }
        return dset;
    }
    /*public DataSet getData1(XmlNode xmlnodeinput)
    {
        if (xmlnodeinput != null)
        {
            XmlTextReader xtr = new XmlTextReader(xmlnodeinput.OuterXml, XmlNodeType.Element, null);
            //dataset = new DataSet();
            dset1.ReadXml(xtr);
        }
        return dset1;
    }*/
    
}

No comments:

Post a Comment