We help IT Professionals succeed at work.

example in multiple sitemap

ANAT2403
ANAT2403 asked
on
620 Views
Last Modified: 2013-11-07
In ASP.NET 2.0 with C# I needs an example to see how to deal with multiple site Map
I don;t want to switch between the sitemap files but I want to use one file in a certain place and another file in another place.
I thought of declaring a main web.sitemap like this:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
      <siteMapNode  title="rootHome"  url="~/default.aspx?p=304" description="">
            <siteMapNode siteMapFile="source.sitemap" />
            <siteMapNode siteMapFile="Everything.sitemap" />
      </siteMapNode>
</siteMap>
and then use it as requested.
In the code behind I tried to have a loop to have data only on the source file but I get problems in the looping
Thankyou
Anat
Comment
Watch Question

Top Expert 2007

Commented:
So, to get this right, you need to be able to traverse the nested sitemaps in your codebehind?

The declarative controls all deal with this automatically.

What is the goal of your code-behind?
Top Expert 2007
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Top Expert 2007

Commented:
The following code if passed the SiteMap.RootNode will render a nested bulleted list which should depict the entire site including all sub sitemap files

    private void ProcessChildNodes(SiteMapNode node)
    {
        Response.Write("<ul>\r\n");
        foreach (SiteMapNode childNode in node.ChildNodes)
        {
            Response.Write("<li>" + childNode.Title + "</li>\r\n");
            if (childNode.ChildNodes.Count > 0)
            {
                ProcessChildNodes(childNode);
            }
        }
        Response.Write("</ul>\r\n");
    }

Author

Commented:
I will explain again:
I have in the web.sitemap 2 sitemap file. suppose I want to show in a menu bar the content of source.sitemap
 and in a left pane the everything.sitemp.
The dealing with source.sitemap is done in thte code behind but I want to deal only with the first node of web.sitemap. The dealing with the everything sitempais done by a repeater directly  in a code and there th question is how to declare it?
this is the way I declared it:


             <asp:Repeater runat="server" ID="LeftMenu"   DataSourceID="SiteMapDataSource1">
                        <ItemTemplate>
                            <div class="field_line_wrap">
                                <div class="field_header">
                                    <asp:HyperLink ID="HyperLink1" runat="server"  NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %>
                                    </asp:HyperLink>
                                </div>
 
                                <asp:Repeater runat="server" ID="LeftsubMenu"     DataSource='<%# ((SiteMapNode) Container.DataItem).ChildNodes %>'>
                                    <ItemTemplate>
                                        <div class="field_products">
                                           <asp:HyperLink ID="HyperLink2" runat="server"  NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %>
                                           </asp:HyperLink>
                                        </div>
                                                    <div class="separator">|</div>
                                   </ItemTemplate>
                                </asp:Repeater>
                            </div>
                        </ItemTemplate>
                </asp:Repeater>
             
                     
Top Expert 2007

Commented:
The contents of everything.sitemap is a sibling of source.sitemap not a child node as your implimentation requires
Top Expert 2007

Commented:
I assume that For each node in source.sitemap there is a number of child nodes which you have stored in Everything.Sitemap?

Does Everything.Sitemap contain all nodes? including all nodes in source.sitemap?

I think if you Structure the sitemap so that it maps to the correct hierachy of your site the code sample above should work?

Author

Commented:
Hi,
I don't want that the source.sitemap and everything .sitemap will be connected.
I want to have in my site 2 independent sitemaps that will be used in the same page. but because I know the rule that every sitemap has to have one web.sitemap I thought of putting them together. but I need to 2 seperate sitemaps. how do I implement this? Maybe I should start from a different direction. Please advise!
Anat
Top Expert 2007

Commented:
Why do you need two seperate site maps? I don't think you are using the site map as intended? Could you post the contents of the two sitemaps so I can get a feel for why you have taken the approach you have?
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.