Insert Paragraph in new line

Do you want to: Ask a how-to question

Hey @Alexandre,
I have another query :slight_smile:
I have been trying to insert a new content control in a new line. Suppose my cursor is inside a paragraph and need to insert a new content control as a next paragraph, i can do executeMethod - movecursortoend to go to the last of that paragraph and use insertcontent method to add a new paragraph but how do i make sure it enters in a new line because if the user cursor is already inside any paragraph which has content control, it will take cursor to end of that paragraph but within that existing content control and it will make the new content control within the existing one, how do we handle CC to be always created on new line

Any help would be appreciated

Also @Alexandre it seems that MoveCursorToEnd always takes the cursor to end of document instead of current paragraph

Hello @agamdev

Indeed, MoveCursorToEnd() places cursor to the end of the document. Do I understand that according to your usage scenario new paragraph must be inserted after current one and being the last in the document? Or there is another paragraph after current one with Content Control and you want to insert new paragraph in between?

Hi @Constantine According to docs, from what i understood is that MoveCursorToEnd should take the cursor to end of document is parameter passed is true, otherwise it should take it to end of paragraph just like word

Actually my requirement is to create a paragraph/empty content control in new line always whether there is another paragraph after that or not. if there is another para, it should add in between.

No, editing areas are separated as document body, footer/header, footnote, or autoshape which means that if cursor is in the text (document body) it will place cursor to the end of the document only. This method cannot place it to the end of paragraph where cursor is currently located.

In general, there is no direct method to obtain whole paragraph, but this can be implemented in such way:

var oDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph(); 
oParagraph.AddText("This is a sample text. It was inserted here.");
var oBlockLvlSdt = oParagraph.InsertInContentControl(1); // Define new para as Content Control
oDocument.InsertContent([oBlockLvlSdt], false); // Insert Content Control

// Concatenate next and previous paragraphs 
var oNextParagraph = oParagraph.GetNext();
var oText = oNextParagraph.GetText();
oNextParagraph.Delete();
var oPreviousParagraph = oParagraph.GetPrevious();
oPreviousParagraph.AddText(oText);

This sample creates new paragraph with some text, wraps it into a Content Control, then it separates current paragraph to insert this Content Control and concatenates next part of the paragraph with previous one. As a result, a Content Control is added as a next new separate paragraph.

Main methods used: InsertContent, GetNext, GetPrevious and InsertInContentControl.