C# .NET - Inserting page break in MS word using C#

Asked By Anjali agarwal on 20-Jan-13 02:12 PM

hi all,

 I exported  a gridview in ms word document in C#. I want to insert page breaks in that MS word document using C# windows application . I want the page break to appear wherever
--PAGE BREAK-- is written in the ms word document.

Also, I want to insert a header and footer on each page that says "THIS IS A DRAFT"

How can I acheive this is C# windows application.

Thanks.

White Ashlin replied to Anjali agarwal on 21-Jan-13 01:55 AM
Use this word library on codeplex: http://netword.codeplex.com/ you can perform your task as below code:

Document document = new Document(); 
document.LoadFromFile(@"E:\.NET Framework.docx"); document.Sections[0].Paragraphs[3].AppendBreak(BreakType.PageBreak); document.SaveToFile("PageBreak.docx", FileFormat.Docx2010);