Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > RelatedDocuments View modes: 
User avatar
Member
Member
robert-tailor.co - 9/6/2012 6:49:49 PM
   
RelatedDocuments
I'm trying to understand the logic behind Related Documents in CMSDesk.

Let's say I've got a document ('docA'), and I've used the CMSDesk to relate it to another document ('docB').

Now I want to list all related documents when 'docA' is rendered.

In my code, I tried using what I thought was the obvious choice:

CMSContext.CurrentDocument.RelatedDocuments


I figured this would contain a collection of related documents, and that I could use standard array selectors to select my related documents. E.g.:

CMSContext.CurrentDocument.RelatedDocuments[0]


I was wrong. The above code returns NULL every time. And this:

CMSContext.CurrentDocument.RelatedDocuments.Count


Always returns '0' (zero).

*BUT*, the following code returns a value:

CMSContext.CurrentDocument.RelatedDocuments.FirstOrDefault()


Why would this work, but not the previous line of code. It means that to select the first related document, I have to use the following code:

CMSContext.CurrentDocument.RelatedDocuments.FirstOrDefault()[0]


This seems weird and dumb to me.

Can someone explain why CMSContext.CurrentDocument.RelatedDocuments hasn't simply been implemented as a standard list? What is the logic behind all this?

Thanks.

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 9/11/2012 4:30:08 AM
   
RE:RelatedDocuments
Hi,


if you want to get related documents by API, please use the SelectNodes method that has overloaded versions with parameters for relationships (please see the API reference, or use intelisense).

I will ask our developers what is the goal and usability of RelatedDocuments and let you know.


Best regards,
Helena Grulichova

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 9/11/2012 6:43:54 AM
   
RE:RelatedDocuments
Hi again,


the RelatedDocuments is a collection of sets of particular relationships (you can define them in Site Manager -> Development -> Relationship names). It means that if you want to get a collection of nodes that are related by the "isrelatedto" relationship, you can use:

node.RelatedDocuments["isrelatedto"]

Then you can loop this collection by the foreach cycle, for example:

foreach (TreeNode node in CMSContext.CurrentDocument.RelatedDocuments["isrelatedto"])
{
...

and work with the particular TreeNode objects. I hope it helps.


Best regards,
Helena Grulichova


User avatar
Member
Member
robert-tailor.co - 9/11/2012 3:48:46 PM
   
RE:RelatedDocuments
OK - thanks for the info Helena.