StructuredDocumentTagRemoveSelfOnly Method

Removes just this SDT node itself, but keeps the content of it inside the document tree.

Namespace:  Aspose.Words.Markup
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.3
Syntax
public void RemoveSelfOnly()
Examples
Shows how to create a StructuredDocumentTag in the form of a plain text box and modify its appearance.
// Create a new document 
Document doc = new Document();

// Create a StructuredDocumentTag that will contain plain text
StructuredDocumentTag tag = new StructuredDocumentTag(doc, SdtType.PlainText, MarkupLevel.Inline);

// Set the title and color of the frame that appears when you mouse over it
tag.Title = "My plain text";
tag.Color = Color.Magenta;

// Set a programmatic tag for this StructuredDocumentTag
// Unlike the title, this value will not be visible in the document but will be programmatically obtainable
// as an XML element named "tag", with the string below in its "@val" attribute
tag.Tag = "MyPlainTextSDT";

// Every StructuredDocumentTag gets a random unique ID
Assert.That(tag.Id, Is.Positive);

// Set the font for the text inside the StructuredDocumentTag
tag.ContentsFont.Name = "Arial";

// Set the font for the text at the end of the StructuredDocumentTag
// Any text that's typed in the document body after moving out of the tag with arrow keys will keep this font
tag.EndCharacterFont.Name = "Arial Black";

// By default, this is false and pressing enter while inside a StructuredDocumentTag does nothing
// When set to true, our StructuredDocumentTag can have multiple lines
tag.Multiline = true;

// Insert the StructuredDocumentTag into the document with a DocumentBuilder and save the document to a file
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertNode(tag);

// Insert a clone of our StructuredDocumentTag in a new paragraph
StructuredDocumentTag tagClone = (StructuredDocumentTag)tag.Clone(true);
builder.InsertParagraph();
builder.InsertNode(tagClone);

// We can remove the tag while keeping its contents where they were in the Paragraph by calling RemoveSelfOnly()
tagClone.RemoveSelfOnly();

doc.Save(ArtifactsDir + "StructuredDocumentTag.PlainText.docx");
See Also