Getting url of contentfolder

Vote:
 

I have had some problems getting the url for contentfolders and contentassetfolders.


As an example, this returns null(the parent is a folder):

UrlResolver.Current.GetUrl(file.ParentLink);

    

This however works fine:

UrlResolver.Current.GetUrl(file.ContentLink);

    

Do i need to treat folders differently?

#79786
Jan 07, 2014 10:08
Vote:
 

Have you added any templates for ContentFolder?

#79787
Edited, Jan 07, 2014 10:19
Vote:
 

I have not :/

#79788
Jan 07, 2014 10:33
Vote:
 

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).

#79826
Jan 08, 2014 11:36
Vote:
 

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.

#79976
Jan 13, 2014 9:55
Vote:
 

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});



#115386
Edited, Jan 14, 2015 12:20
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.