How to copy the heading1 below the content not position 2 heeding 1. then past it to position 2 heeding 1.
Please find the below mention input and expected output word document.
Input123 (2).docx (24.8 KB)
Expected_output123.docx (20.0 KB)
Please find the below code I used.
string headingToFind = "HEADING ARE";
bool headingIsMissing = true;
int position = 2;
var list = doc.GetChildNodes(NodeType.Paragraph, true).Cast<Paragraph>();
var listHeadings = list.Where(p => p.IsListItem && p.ParagraphFormat.StyleIdentifier == StyleIdentifier.Heading1);
bool isPositionFound = true;
foreach (Paragraph paragraph in listHeadings)
{
paragraph.JoinRunsWithSameFormatting();
foreach (Run run in paragraph.Runs)
{
// search for the heading
if (run.Text.Equals(headingToFind, StringComparison.InvariantCultureIgnoreCase))
{
int listItemPosition = 0;
foreach (var para in listHeadings)
{
listItemPosition++;
if (listItemPosition != position)
{
//Kindly help me here
}
}
}
}
}