VB.NET - display sitemap.xml in table format

Asked By hiral jani on 07-Sep-11 01:47 AM
Hello,

I have 1 web application & in that I need to generate one sitemap.xml.
I have huge amount of URL's .I want to create sitemap.xml but want to display it in table format like the one used in wordpress.

Kindly give some suggestion along with some code / example.
Jitendra Faye replied to hiral jani on 07-Sep-11 03:43 AM
The simplest way to create a site map is to create an XML file named Web.sitemap that organizes the pages in the site hierarchically. This site map is automatically picked up by the default site-map provider for ASP.NET.


The Web.sitemap file must be located in the application root directory, though it can reference other site-map providers, or other site-map files in other directories as long as those files are in the same application.



Example-


<siteMap>
  <siteMapNode title="Home" description="Home" url="~/default.aspx">
    <siteMapNode title="Products" description="Our products"
    url="~/Products.aspx">
    <siteMapNode title="Hardware" description="Hardware choices"
      url="~/Hardware.aspx" />
    <siteMapNode title="Software" description="Software choices"
      url="~/Software.aspx" />
    </siteMapNode>
    <siteMapNode title="Services" description="Services we offer"
      url="~/Services.aspx">
      <siteMapNode title="Training" description="Training classes"
      url="~/Training.aspx" />
      <siteMapNode title="Consulting" description="Consulting services"
      url="~/Consulting.aspx" />
      <siteMapNode title="Support" description="Supports plans"
      url="~/Support.aspx" />
    </siteMapNode>
  </siteMapNode>
</siteMap>

Hope this will help you.
dipa ahuja replied to hiral jani on 07-Sep-11 03:56 AM
Untitled document

 
Add new siteMap file in your file that is web.sitemap:
 
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
 <siteMapNode url="Default.aspx" title="Home"  description="This is home page">
 <siteMapNode url="Default2.aspx" title="Child1"  description="Child1" />
 <siteMapNode url="Default3" title="Child2"  description="Chil2" />
 </siteMapNode>
</siteMap>
Now Add Tree Control + SiteMapDataSource and set the Datasource property of TreeView:
 
<asp:TreeView ID="TreeView2" runat="server" DataSourceID="SiteMapDataSource1">
</asp:TreeView>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
 
Radhika roy replied to hiral jani on 07-Sep-11 01:06 PM
Follow this example , here i am creating menu using xml file.

xml file-

<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
 <siteMapNode url="Default.aspx" title="Home">
   <siteMapNode title="Products" description="Our Products">
    <siteMapNode url="Product1.aspx" title="My Products" 
      description="These are my products" />
    <siteMapNode url="Product2.aspx" title="New Products" 
      description="Some new products " />
   </siteMapNode>
   <siteMapNode title="Services" description="Our Services">
    <siteMapNode url="Service1.aspx" title="http://asp.net/ Consulting"
      description="Best http://asp.net/ Consulting" />
    <siteMapNode url="Service2.aspx" title="http://asp.net/ Training" 
      description="Best http://asp.net/ Training" />
   </siteMapNode>
 </siteMapNode>
</siteMap>

Now use this code to design menu using xml.


private void CreateMenuWithXmlFile()
{
  string path = @"C:\MyXmlFile.xml";
  DataSet ds = new DataSet();
  ds.ReadXml(path);
  Menu menu = new Menu();
  menu.MenuItemClick += new MenuEventHandler(menu_MenuItemClick);

  for (int i = 0; i < ds.Tables.Count; i++)
  {
    MenuItem parentItem = new MenuItem((string)ds.Tables[i].TableName);
    menu.Items.Add(parentItem);

    for (int c = 0; c < ds.Tables[i].Columns.Count; c++)
    {
    MenuItem column = new MenuItem((string)ds.Tables[i].Columns[c].ColumnName);
    menu.Items.Add(column);

    for (int r = 0; r < ds.Tables[i].Rows.Count; r++)
    {
      MenuItem row = new MenuItem((string)ds.Tables[i].Rows[r][c].ToString());
      parentItem.ChildItems.Add(row);
    }
    }
  }

  Panel1.Controls.Add(menu);
  Panel1.DataBind();
}

follow this link also-

http://www.codeproject.com/KB/menus/PopulatingMenuControlASP2.aspx


Hope this will help you.