Create relationship between Pages Pro-grammatically using Kentico 8.2 API

Chaudhary Zulfiqar asked on November 18, 2015 23:29

Hi. I Manage to import the data by using Kentico 8.2 API as a pages. The imported data as a Pages need to have a Related pages i.e. relationship between the sub pages as well. I imported Users based on Region and the user has a multiple offices (which is Related pages in my case on a main user page). My Question is how can i define the relationship between the page and the related pages pro-grammatically? I cant do it manually because it's a lot of data i.e. 20000 + Users?

Thank you Charsi

Correct Answer

Brenden Kehren answered on November 19, 2015 00:13

Direct from the API Examples:

private bool CreateRelationship()
{
    // Get the relationship name
    RelationshipNameInfo relationshipName = RelationshipNameInfoProvider.GetRelationshipNameInfo("MyNewRelationshipName");
    if (relationshipName != null)
    {
        // Get the tree structure
        TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);

        // Get documents for relationship (the Root document is used for both in this example) 
        TreeNode root = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/", null, true);

        // Create the relationship between documents
        RelationshipInfoProvider.AddRelationship(root.NodeID, root.NodeID, relationshipName.RelationshipNameId);

        return true;
    }

    return false;
}
0 votesVote for this answer Unmark Correct answer

Recent Answers


Chaudhary Zulfiqar answered on November 20, 2015 16:59

Thank you Brenden!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.