Hello,
The node in the content tree is identified as linked, if it has the property
NodeLinkedNodeID defined. If it's null, node is not a linked document.
So, you can use a custom
TreeNode handler and check whether the new document is the banner added to the original folder and if so, find all documents in the content tree that has
NodeLinkedNodeID set to the
NodeID of the parent folder. Than you can use
TreeNode.InsertAsLink method to create a new linked document.
So, in general the code could look like the following one:
public override void OnAfterInsert(object treeNodeObj, int parentNodeId, object tree)
{
// INSERT YOUR CUSTOM AFTER-INSERT CODE
UserInfo ui = UserInfoProvider.GetUserInfo("administrator");
CMS.TreeEngine.TreeProvider provider = new CMS.TreeEngine.TreeProvider(ui);
provider.MergeResults = true;
TreeNode newDoc = treeNodeObj as TreeNode;
// check the parent document
if (newDoc.NodeAliasPath.StartsWith("/Banners/") && provider != null)
{
TreeNode parentDoc = newDoc.Parent;
// get all linked document of the parent document
DataSet ds = provider.SelectNodes("SiteName", "/%", "en-us", true, "", "NodeLinkedNodeID = " + parentDoc.NodeID.ToString());
if (ds != null)
{
TreeNode linkedDoc = null;
foreach (DataRow row in ds.Tables[0].Rows)
{
// create linked document
linkedDoc = provider.SelectSingleNode( ValidationHelper.GetInteger(row["NodeID"], 0));
if (linkedDoc != null)
{
newDoc.InsertAsLink(linkedDoc.NodeID);
}
}
}
}
}
If you need more information about creating a linked document using API, I would like to point you to the following section of Developer's guide and to our API reference:
API reference,
Create linked documentBest regards,
Michal Legen