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

Free Support Forum - aspose.com

ToTxt obsolete

I use Aspose.Words for .NET 15.12.0 to parse document and look for Heading 1 text with certain content. So, I use this code:

Dim paragraphs as NodeCollection = myDoc.GetChildNodes(NodeType.Paragraph, True)
For Each p as Paragraph in paragraphs
If p.ParagraphFormat.Style.Name = “Heading 1” Then
If p.ToTxt = “MY SEARCH” Then

In Visual Studio, I have message say “ToTxt is obsolete. Use ToString(SaveFormat.Text) instead”. I replace ToText with ToString(SaveFormat.Text), but it returns “Aspose.Words.Paragraph” instead of the heading content (like “MY SEARCH”). Is this a bug or I use the method ToString(…) incorrectly? On the other hand, ToTxt returns the heading content correctly (like “MY SEARCH” ) even though it says it’s obsolete.

Hi there,

Thanks for your inquiry. Please use Node.ToString method instead of Node.ToText. Node.ToText method is obsolete now.

Could you please attach your input Word document here for testing? We will investigate the issue on our side and provide you more information.

Here are my input document for parsing, the code, and output.

Hi there,

Thanks for sharing the detail. Please replace paragraph.ToString() with paragraph.ToString(SaveFormat.Text) in your code to get the required output. Node.ToString(SaveFormat) method exports the content of the node into a string in the specified format. Please let us know if you have any more queries.