This project has moved. For the latest updates, please go here.

Exploring document

Mar 13, 2015 at 2:34 PM
Hi everyone,
I need to explore a document to replace text in a different way whether it's in a table or not.
I can use the Tables property to scan text in tables, but how can I search outside tables?

I need something like that (pseudocode):
foreach (partOfDocument in Document) {
    if (partOfDocument.IsTable) {
        ...do something...
    } else {
        ...do semething else...
    }
}
Any idea how could I solve this problem?

Thanks
Mar 16, 2015 at 8:25 AM
You could check if the paragraph's ParentContainer is a Cell, which means the paragraph is inside a table.
You can loop through all paragraphs and check the ParentContainer type like this:
using (DocX doc = DocX.Load(document))
{
    foreach (Paragraph p in doc.Paragraphs)
    {
        if (p.ParentContainer.Equals(ContainerType.Cell))
        {
            //Paragraph is inside a table
        }
    }
}
Marked as answer by miles78 on 3/18/2015 at 7:15 AM