How do I use a treeview with a sitemap file from another web site?

  • Thread starter Thread starter Alan Silver
  • Start date Start date
A

Alan Silver

Hello,

I want to show a treeview display of the contents of a sitemap file on
another web site, chosen according to the currently logged on user. I
know at run time the path to the sitemap file, but this cannot be
determined at design time as it depends who logs in.

Can I do this? I can't see how without writing my own provider, which
seems like a lot of work for such a simple request?

TIA
 
Thanks for the reply. Sorry, I wasn't clear what I meant.

I have full access to the server, and both web sites are on the same
server, so accessing the sitemap file itself is just a case of getting
the right path, which is easy.

My question was more how to load a sitemap file that isn't called
"web.sitemap" in the current web site. The SiteMapDataSource doesn't
seem to have an option for specifying the sitemap file to use, it just
assumes that you want to use the current site's "web.sitemap." I would
like to know if there is a way of loading a different sitemap file (even
another one in the same web site for that matter) so it can be used.

Thanks for the reply. Any further help appreciated.
use:

System.Net.WebClient wc = new System.Net.WebClient();
byte[] response = wc.UploadData("http://address.com/settingsFile?user=" +
userId, "GET", null);

string strResponse = System.Text.Encoding.ASCII.GetString(response);
 
Does this help

Partly, and partly not. Is it possible to specify the file in at
run-time? The situation is that I have an admin site that is used by
people who use my e-commerce package. There is one admin site, and this
is used by everyone. They log in, and the user name is used to identify
the path to the root directory of their web site. I want to use that
path to load up their web.sitemap file.

I don't really want to add the sitemap files to the web.config file as
this means duplicating information, which is bound to cause problems. At
the moment, there is one config file per site, living in the App_Data
folder of the site. The admin site knows the path to each site, so it
can just pick up the config file, and anything else it wants from the
user site.

What I would really like is some way of telling the SiteMapDataSource
(or similar) at run-time which sitemap file to load. This seems to
simple and obvious, but I can't see how to do it.

Any further suggestions appreciated. Thanks again.
 
You might have to create a customer SiteMapProvider, and if you go through
all that trouble you might want to think about incorporating it into your
database, since the siteMap will be based on the user.

http://msdn2.microsoft.com/library/system.web.sitemapprovider.aspx
Look at the LoadSiteMapFromStore function

Thanks for that.

It occurred to me that maybe I'm thinking about this the wrong way. The
web.sitemap file is just an XML file, so maybe I should just declare an
XmlDataSource and set the DataFile property to the web.sitemap file. I
can then use the XmlDataSource as the data source for the tree view.

This turned out to be very easy!! Sample code is shown below...

<asp:TreeView id="BookTreeView" DataSourceID="BookXmlDataSource"
runat="server">
<DataBindings>
<asp:TreeNodeBinding DataMember="siteMapNode" TextField="Title"/>
</DataBindings>
</asp:TreeView>

<asp:XmlDataSource id="BookXmlDataSource"
DataFile="D:\WebSites\TestSite\web.sitemap" runat="server" />

This has the path to the file hard-coded for testing. In the real code,
I would just do that bit at run-time.

All I have to do now is work out how to control the treeview. I would
like to start the treeview displaying at the first SiteMapNode, ignoring
the SiteMap node that is at the root of the sitemap file. Any ideas
about this?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top