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

Free Support Forum - aspose.com

I want to insert a paragraph before a table

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

but it’s insert the paragraph into the first cell.

Have you a solution ?

Christophe Mari

Hi Christophe,

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);

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