How to find a textbox

Hi,

I want to find all textboxes in a header or footer and remove them but ignoring textboxes in the body.
I have attached here an example
textbox in footer.zip (103.2 KB)

Thanks in advance
Guido

@Nachti There are no textboxes in your document, there are text frames. You can use the following code to achieve what you need:

Document doc = new Document(@"C:\Temp\in.docx");

foreach (Paragraph p in doc.GetChildNodes(NodeType.Paragraph, true))
{
    // Check whter paragraph is in header/footer
    if (p.GetAncestor(NodeType.HeaderFooter) != null)
    {
        // Check whether the paragraph is text frame.
        if (p.FrameFormat.IsFrame)
            p.Remove();
    }
}

doc.Save(@"C:\Temp\out.docx");

Thank you.

Here is example with a textbox. It is different to the current code ?

unsupported footer items.zip (104.9 KB)

Regards,
@Nachti

@Nachti In this case the code is a little different. Since text boxes are shapes. Please see the following code:

Document doc = new Document(@"C:\Temp\in.docx");

foreach (Shape s in doc.GetChildNodes(NodeType.Shape, true))
{
    // Check whter shape is in header/footer
    if (s.GetAncestor(NodeType.HeaderFooter) != null)
    {
        // Check whether the shape is text box.
        if (s.ShapeType == ShapeType.TextBox)
            s.Remove();
    }
}

doc.Save(@"C:\Temp\out.docx");