@nethmi In your case you can check whether list neighbor list items belong to the same list. For example see the following code:
Document doc = new Document(@"C:\Temp\in.docx");
// Get all paragraphs, which are list items.
List<Paragraph> listItems = doc.GetChildNodes(NodeType.Paragraph, true)
.Cast<Paragraph>().Where(p => p.IsListItem).ToList();
// Set keep with next flag if the next paragraph belongs to the same list.
foreach (Paragraph item in listItems)
{
// Set keep lines togather for all list items.
item.ParagraphFormat.KeepTogether = true;
Paragraph nextPara = item.NextSibling as Paragraph;
if (nextPara != null && nextPara.IsListItem && nextPara.ListFormat.List == item.ListFormat.List)
item.ParagraphFormat.KeepWithNext = true;
}
doc.Save(@"C:\Temp\out.docx");
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.