NodeToString Method (SaveFormat)
Exports the content of the node into a string in the specified format.

Namespace: Aspose.Words
Assembly: Aspose.Words (in Aspose.Words.dll) Version: 19.9
public string ToString(
	SaveFormat saveFormat


Type: Aspose.WordsSaveFormat

Return Value

Type: String
The content of the node in the specified format.
Exports the content of a node to String in HTML format using default options.

Document doc = new Document(MyDir + "Document.doc");

// Extract the last paragraph in the document to convert to HTML.
Node node = doc.LastSection.Body.LastParagraph;

// When ToString is called using the SaveFormat overload then conversion is executed using default save options. 
// When saving to HTML using default options the following settings are set:
//   ExportImagesAsBase64 = true
//   CssStyleSheetType = CssStyleSheetType.Inline
//   ExportFontResources = false
String nodeAsHtml = node.ToString(SaveFormat.Html);
Shows the difference between calling the GetText and ToString methods on a node.

Document doc = new Document();

// Enter a dummy field into the document.
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertField("MERGEFIELD Field");

// GetText will retrieve all field codes and special characters
Console.WriteLine("GetText() Result: " + doc.GetText());

// ToString will export the node to the specified format. When converted to text it will not retrieve fields code 
// or special characters, but will still contain some natural formatting characters such as paragraph markers etc. 
// This is the same as "viewing" the document as if it was opened in a text editor.
Console.WriteLine("ToString() Result: " + doc.ToString(SaveFormat.Text));
Shows how to extract the label of each paragraph in a list as a value or a String.

Document doc = new Document(MyDir + "Lists.PrintOutAllLists.doc");
int listParaCount = 1;

foreach (Paragraph paragraph in doc.GetChildNodes(NodeType.Paragraph, true).OfType<Paragraph>())
    // Find if we have the paragraph list. In our document our list uses plain arabic numbers,
    // which start at three and ends at six.
    if (paragraph.ListFormat.IsListItem)
        Console.WriteLine("Paragraph #{0}", listParaCount);

        // This is the text we get when actually getting when we output this node to text format. 
        // The list labels are not included in this text output. Trim any paragraph formatting characters.
        String paragraphText = paragraph.ToString(SaveFormat.Text).Trim();
        Console.WriteLine("Exported Text: " + paragraphText);

        ListLabel label = paragraph.ListLabel;
        // This gets the position of the paragraph in current level of the list. If we have a list with multiple level then this
        // will tell us what position it is on that particular level.
        Console.WriteLine("Numerical Id: " + label.LabelValue);

        // Combine them together to include the list label with the text in the output.
        Console.WriteLine("List label combined with text: " + label.LabelString + " " + paragraphText);

See Also