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

Free Support Forum - aspose.com

Aspose Document removes "\n"


I am having a strange issue where after creating a document and writing some text, all the “\n” are removed.
So when we display the content in our UI (WinForms), there are no new lines.

Let’s say I create a new object with this text (with line breaks):

This is automated
Client Name - Test Client, Test Client
Matter Reference - 220001

In the background that’s is equal to : “This is automated\r\nClient Name - Test Client, Test Client\r\nMatter Reference - 220001\r\nTest\f”;

When I create the aspose word document and assign that text, the document.Range.Text becomes “This is automated\rClient Name - Test Client, Test Client\rMatter Reference - 220001\rTest\f”.

So in our interface, everything will be displayed in one line, which is annoying.

This is a basic example of that behaviour:

using System;
using System.IO;
namespace AsposeNewLines
    internal class Program
        static void Main(string[] args)
            string text = "This is automated\r\nClient Name - Test Client, Test Client\r\nMatter Reference - 220001\r\nTest\f";

            Aspose.Words.Document document = new Aspose.Words.Document();
            Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(document);
            string filename = string.Format(@"{0}\{1}.doc", Path.GetTempPath(), Guid.NewGuid().ToString());

            document = new Aspose.Words.Document(filename);
            text = document.Range.Text;

@cesypozo In your case you should use Node.ToString method to get text of the document. Please see the following code:

text = document.ToString(SaveFormat.Text);

When you use Range.Text paragraph breaks are represented as \r characters. This is an expected behavior. See ControlChar constants.

1 Like

Thanks a million for your response.

That solved my problem.

1 Like