API Questions on Kentico API.
Version 6.x > API > Why is the TreeNode.NodeAliasPath Property Read Only? View modes: 
User avatar
Member
Member
scott_hancock-urmc.rochester - 8/23/2012 1:50:04 PM
   
Why is the TreeNode.NodeAliasPath Property Read Only?
We're writing some code to add new pages using the API, and hit a snag when we tried to make the node alias path different from the Document Name. We found the TreeNode.NodeAliasPath property is read only but we were able to set it using TreeNode.SetValue. See the code below. Why is tn.NodeAliasPath read only? Is there any reasone we shouldn't be using tn.SetValue? Can we set this when we are creating the document or should we create the document first and then change it?

TreeProvider tree = new TreeProvider(User);
TreeNode tn = tree.SelectSingleNode(nodeID);
//tn.NodeAliasPath = newpath; // Property is read only!
tn.SetValue("NodeAliasPath", newPath);
DocumentHelper.UpdateDocument(tn, tree);

Thanks,
Scott

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 8/24/2012 8:09:29 AM
   
RE:Why is the TreeNode.NodeAliasPath Property Read Only?
Hello,

I've checked with our developer and the NodeAliasPath property is a system property used in methods which manipulate with the TreeNode object and that's why it is set to be read only. You can keep using the SetValue method to update it.

Best regards,
Boris Pocatko

User avatar
Certified Developer 8
Certified Developer 8
Jiveabillion - 8/24/2012 12:44:13 PM
   
RE:Why is the TreeNode.NodeAliasPath Property Read Only?
You should use tn.NodeAlias = newAlias instead. It's much safer because it just changes the last part of the path.

Imagine if you somehow changed the NodeAliasPath to something that didn't match the paths of the documents parents? That would be a problem. The NodeAliasPath is "calculated" based upon the concatenation of all of the document's ancestors' NodeAliases, which is, I believe, the real reason they made it readonly.

If you do, however, want to change the path to the document to be something that is different than it's logical path from it's ancestors, you can set the DocumentUrlPath property or add a DocumentAlias to your document.