I want to insert a paragraph before a table

Hi
I had a file with only a table and I want to insert a paragraph before.
I’m trying:

builder.MoveToDocumentStart();
builder.InsertParagraph();
but it’s insert the paragraph into the first cell.

Have you a solution ?

Regards,
Christophe Mari

Hi Christophe,

Thanks
for your inquiry. DocumentBuilder.MoveToDocumentStart moves the cursor to the beginning of the document. In your case, the cursor should be in first cell of table. Please use the following code example to achieve your requirements and let us know if you have any more queries.

Document doc = new Document(MyDir + “10 lignes.docx”);
DocumentBuilder builder = new DocumentBuilder(doc);

if (doc.FirstSection.Body.FirstChild.NodeType == NodeType.Table)
{
    //Insert empty paragraph at the start of document
    doc.FirstSection.Body.InsertBefore(new Paragraph(doc), doc.FirstSection.Body.FirstChild);
    builder.MoveToDocumentStart();
}

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