I wonder whether there is a workaround for using the standard XmlSiteMapProvider within a non application, like WinForm/Console or, in my case, VS Unit Test one.

The following code fails, because it cannot create a path to the .sitemap file inside a private GetConfigDocument method.

XmlSiteMapProvider provider = new XmlSiteMapProvider(); NameValueCollection providerAttributes = new NameValueCollection(); providerAttributes.Add("siteMapFile", "Web.sitemap"); provider.Initialize("XmlSiteMapReader", providerAttributes); provider.BuildSiteMap();

I feel the right solution is to write another provider.

+2  A: 

I do not see why not. It is just a provider that implements an interface. You may not need many of the features, but you can access the API for what it provides you. Your WinForms screens can simply use the Urls for identification so that you can determine your place in the hierarchy.

What you may have to do is create a custom implementation of the provider because it will use the HttpContext to get the Url of the current web request to identify current placement while you will need to get that value differently. That is what could be tricky because your WinForm application could be displaying multiple windows at time. If you know there is only one window showing at a time you could use a static value which is set prior to accessing the SiteMap API.

Now you have to question the value of using an API if you have to do all of the work. There may not be enough benefit to make it worthwhile.