We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Deleting Header / Footer from all sections within a document

Hi,
Could you please let me know how to delete all the headers and footers from sections of the entire document?
Thanks.

Hi
Thanks for your request. Please try using the following code:

// Open document
Document doc = new Document(@"Test038\in.doc");
// Loop trough all sections
foreach (Section sect in doc.Sections)
{
    // Remove all headers/footers from current section
    sect.HeadersFooters.Clear();
}
// Save output document
doc.Save(@"Test038\out.doc");

Hope this helps.
Best regards.

Thanks for your reply. I tried it and works great. However, I have to use the following code which sets the Tracking off and works from the Document Builder. How do I use both Document Builder and Document doc together? Thanks.

Dim builder As DocumentBuilder = New DocumentBuilder(doc)
' Turn off revision tracking
With builder.Document
.TrackRevisions = False
End With

Hi
Thanks for your request. DocumentBuilder.Document property returns Document that is processed by DocumentBuilder, i.e. it returns Document that you put as parameter to DocumentBuilder constructor.
Please see the following code:

'Open document and create DocumentBuilder
Dim doc As Document = New Document("C:\Temp\test.doc")
Dim builder As DocumentBuilder = New DocumentBuilder(doc)
'This is the same if you write the following
'With builder.Document
With doc
'Turn off revision tracking 
.TrackRevisions = False
'Loop through all sections in the document and remove headers/footers
For Each sect As Section In .Sections
sect.HeadersFooters.Clear()
Next
End With
'Save document
doc.Save("C:\Temp\out.doc")

Hope this helps.
Best regards.