Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > What is CMSContext.CurrentDocument.DocumentUrlPath and why isn't it always populated? View modes: 
User avatar
Member
Member
robert-tailor.co - 8/3/2012 12:22:56 AM
   
What is CMSContext.CurrentDocument.DocumentUrlPath and why isn't it always populated?
Hi,

What is the best way to reliably get the requested document's "Live URL" in both the CMSDesk and live site?

I have a number of documents for which I need their 'Live' URL, and I thought this could be retrieved using CMSContext.CurrentDocument.DocumentUrlPath. But this often comes out with an empty string.

So, what is CMSContext.CurrentDocument.DocumentUrlPath, what does it reference, and why is it sometimes empty?

And what is the best way to retrieve the document's "Live URL" path displayed in the document's Properties->General tab in CMSDesk?

Thanks.


User avatar
Kentico Support
Kentico Support
kentico_janh - 8/3/2012 12:56:14 AM
   
RE:What is CMSContext.CurrentDocument.DocumentUrlPath and why isn't it always populated?
Hello,

The CMSContext.CurrentDocument.DocumentUrlPath variable contains a value from the Properties -> URLs -> Document URL path property if there is any.

If the CMSContext.CurrentDocument.DocumentUrlPath variable is empty then the Live URL property uses the CMSContext.CurrentDocument.NodeAliasPath (which is never empty), so you can use this variable instead.

Best regards,
Jan Hermann

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 8/6/2012 6:26:36 PM
   
RE:What is CMSContext.CurrentDocument.DocumentUrlPath and why isn't it always populated?
The method "CMS.Controls.TransformationHelper.HelperObject.GetDocumentUrl" has 3 overloads so you can pass it the documentid,nodealiaspath,and documenturlpath. If you pass it all three, then it doesn't have to query the tree to get the url, it will return the nodealiaspath plus your default document extension if the documenturlpath is null or empty. If you just pass it the documentid, then it will query the tree and return the documenturlpath if it isn't empty and the nodealiaspath if it is.

Thats the gist of it anyway.

User avatar
Member
Member
robert-tailor.co - 8/6/2012 6:28:13 PM
   
RE:What is CMSContext.CurrentDocument.DocumentUrlPath and why isn't it always populated?
Cool. Thanks for your help!

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 8/7/2012 12:38:55 PM
   
RE:What is CMSContext.CurrentDocument.DocumentUrlPath and why isn't it always populated?
You can also use CMSContext.GetUrl(aliaspath,urlpath,sitename), which is more appropriate under most circumstances.