I'm trying to create a string that would be the same as the urlName for a published node - only I need it before the node has been published. I'm need this string in a custom publishing event handler so, at that point, the urlName property hasn't been determined.
Seems like there would be a method I could call where I can pass to it the name of the node that's about to be published and it would return the "calculated" urlName. I've tried to find the code that Umbraco uses (when a node is published) to determine the urlName from the Name property - - but I haven't found it yet.
There is an extension method you can use for this. It's in the Umbraco.Core namespace. After adding that namespace you can do .ToUrlSegment() on any string. If you use that method on the name of the node you'll get the correct value. In newer versions of Umbraco there is also the UrlName property on a node.
Thanks Jeroen for the hint, definitely have to look at the umbraco.core classes in more detail ;-)
Another question regarding umbracoUrlAlias in using in an publishing event: What i'm going to try is, to set the umbracoUrlAlias to the same value as the urlName but that value is for sure not available on IContent. node.Name.ToUrlSegment() works but it's not safe to be a unique url if there are others with the same node.Name.
Is there an easy way to use some umbraco method to get the UrlSegment unique, or do i have to implement my own?
Derive the urlName before a node is published
Hello Umbraco colleagues,
(Umbraco ver 6.1.6)
I'm trying to create a string that would be the same as the urlName for a published node - only I need it before the node has been published.
I'm need this string in a custom publishing event handler so, at that point, the urlName property hasn't been determined.
Seems like there would be a method I could call where I can pass to it the name of the node that's about to be published and it would return the "calculated" urlName. I've tried to find the code that Umbraco uses (when a node is published) to determine the urlName from the Name property - - but I haven't found it yet.
Any suggestions?
Thanks,
David Hill
Hi,
did you find the method for this? Looking at the same "problem" at the moment.
thx,
andreas
Hello,
There is an extension method you can use for this. It's in the Umbraco.Core namespace. After adding that namespace you can do .ToUrlSegment() on any string. If you use that method on the name of the node you'll get the correct value. In newer versions of Umbraco there is also the UrlName property on a node.
Jeroen
Thanks for the information, Jeroen. Even though it has been months since I posted the question, it's very helpful.
Cheers! David
Glad I could help. If it's the answer you were looking for please mark it as the solution.
Jeroen
Thanks Jeroen for the hint, definitely have to look at the umbraco.core classes in more detail ;-)
Another question regarding umbracoUrlAlias in using in an publishing event: What i'm going to try is, to set the umbracoUrlAlias to the same value as the urlName but that value is for sure not available on IContent. node.Name.ToUrlSegment() works but it's not safe to be a unique url if there are others with the same node.Name.
Is there an easy way to use some umbraco method to get the UrlSegment unique, or do i have to implement my own?
thx a lot
Andreas
is working on a reply...