How to replace page breaks with section breaks using .NET

Hi,
I have a document containing page breaks only (so it contains only one section). I need to change the page breaks with section breaks. Reason for that is that I need to change to orientation for some of the pages in my document. I want to do that by looping through the sections and if section.text().Contains("") I want to change the orientation using section.PageSetup.Orientation = Orientation.landscape;

Can you please guide me on how to replace pagebreaks with section breaks.

Thanks in advance,
Ron

Hi Ron,

Thanks for your query. Please use the following code snippet for your requirement. Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "in.docx");


DocumentBuilder builder = new DocumentBuilder(doc);

//Replace PageBreaks with Section breaks


foreach (Paragraph par in doc.GetChildNodes(NodeType.Paragraph, true, false))

{

foreach (Run run in par.Runs)

{

//If run contains PageBreak then remove it and insert section break

if (run.Text.Contains("\f"))

{

builder.MoveTo(run);

builder.InsertBreak(BreakType.SectionBreakContinuous);

run.Remove();

break;

}

}

}

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