

īy executing the program, you will get the output document as follows. Using (FileStream outputFileStream = new FileStream(Path.GetFullPath("./././Sample.docx"), FileMode.Create, FileAccess.ReadWrite))ĭocument.Save(outputFileStream, FormatType.Docx) Ī complete working sample to find and replace text with page break in Word document in C# can be downloaded from GitHub. Replace all entries of a given regular expression text with the text body part.ĭocument.ReplaceSingleLine(new Regex(">"), bodyPart) TextBodyPart bodyPart = new TextBodyPart(document) Paragraph.AppendBreak(BreakType.PageBreak)

Add new paragraph to the document section. Using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx)) Using (FileStream fileStreamPath = new FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
