I am using kentico application where i have to delete all child items which contains either node id of parent or parentnodeid of parent based on the child inside there. Below is the screen shot:
In this picture we can see we have a parent node called membership and inside one child called Blog. Under of Blog which node id is 583 having 29 child. Now I am running a code and getting all the child data under of that parent as a list.
Below is the screen shot:
Now i have to remove all the child data from list whose parentnodeid or parent-parent node id is 583 (Blog).
Below is the code used to get the list of all parent and child items:
TreeProvider tree = new TreeProvider();
var childNodeDataSet = tree.SelectNodes(childNodeId, null, SiteContext.CurrentSiteName);
var getAllChildItems = childNodeDataSet.Items[0].AllChildren;
var getItems = getAllChildItems.ToList().OrderBy(a=>a.NodeAliasPath);
I tried this code to remove the matching parent item from list:
string excludeFileName = "583, 683, 686, 687";
string[] arrStringList = excludeFileName.Split(',');
foreach (var excName in arrStringList)
{
getItems.RemoveAll(a => (a.NodeID == Convert.ToInt32(excName.Trim()) || a.NodeParentID == Convert.ToInt32(excName.Trim()))
|| (a.Parent.NodeID == Convert.ToInt32(excName.Trim()) || a.Parent.NodeParentID == Convert.ToInt32(excName.Trim()))
|| (a.Parent.Parent.NodeID == Convert.ToInt32(excName.Trim()) || a.Parent.Parent.NodeParentID == Convert.ToInt32(excName.Trim()))
|| (a.Parent.Parent.Parent.NodeID == Convert.ToInt32(excName.Trim()) || a.Parent.Parent.Parent.NodeParentID == Convert.ToInt32(excName.Trim())));
}
This code is working fine if i know particular node has how many level.
But if some of the node don't have that much level then in that case this code is giving exception.
If found any issues please let me know.