Delete page on basis of condition


Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them. (51.3 KB)

This is uploaded file. In attachment one file is Original what I’m getting from above code . and one file what I expected.


Thanks for sharing the detail. We are investigating this issue and will get back to you soon.


Please use the following code snippet to get the desired output. Hope this helps you.

Document doc = new Document(MyDir + "Orignal.docx");
//Your code...
//Your code...
//Your code...
if (doc.LastSection.Body.LastParagraph.PreviousSibling.NodeType == NodeType.Paragraph 
    && doc.LastSection.Body.LastParagraph.PreviousSibling.ToString(SaveFormat.Text).Contains("_"))
    ((Paragraph)doc.LastSection.Body.LastParagraph.PreviousSibling).ParagraphFormat.Alignment = ParagraphAlignment.Center;

doc.Save(MyDir + "out.docx");

Thanks a ton ! This all solutions really work for me.