What is the proper way to cast a treenode object into an another object that inherits from a treenode object?
I have the following code but get a cast error at runtime:
public class PublicationWorkflowAction : DocumentWorkflowAction { public override void Execute() { Publication pub = (Publication) Node; }
... public partial class Publication : TreeNode ... protected TreeNode Node ... Exception type: System.InvalidCastException
Currently using Kentico 8.2.11. Thanks in advance.
What is the reason you want to cast it? If this is to fetch data, I'd use node.GetValue("fieldname");
There are many columns on the object and I also have some methods I'd like to encapsulate in the Publication. Overall just want to do this for cleaner and easier code maintenance. Is it possible or is node.GetValue the cleanest route?
@Robert take a look at this post on creating recurring events. This uses a tree node and creates a strongly typed EventDocument. Keep in mind you have to go through the effort and create the class to define the EventDocument.
Please, sign in to be able to submit a new answer.