Currently the UrlResolver will return null for content that does not have a template (this is e.g. that in menus you probably do not want a link that will give 404). However there are cases where you might want the URL anyway so I have reported a bug for this (probably it will be an option on parameter VirtualPathArguments that specifies if templates should be checked for).
Meanwhile you could eiter add a "dummy" template for a folder. Another alternative is to not use UrlResolver but instead directly go against System.Web.Routing.RouteTable.Routes.GetVirtualPath (in that case you should add RoutingContants.NodeKey with the contentreference to the folder in the passed in RouteValues dictionary).
Yea, im working on a file manager where i ned to be able to get the url for folders aswell as content. This is where i ran in to the problem. I can understand the resoning behind the design desition but its not very easy to understand why you get null as a response. So a an extra parameter with a descriptive name would be great.
For now i have created a controller without a view that handles ContentFolders. This seems to be enough to get it working for now.
Just for future reference, now there is no need to implement a dummy templete, instead:
string language = null; var iLocalizable = CurrentPage as ILocalizable; if (iLocalizable != null && iLocalizable.Language != null) { language = iLocalizable.Language.Name; } var deterministicUrl = UrlResolver.Current.GetUrl(file.ParentLink, language, new VirtualPathArguments() { ContextMode = ContextMode.Default, ValidateTemplate = false});
I have had some problems getting the url for contentfolders and contentassetfolders.
As an example, this returns null(the parent is a folder):
This however works fine:
Do i need to treat folders differently?