To reproduce:
Add a RadRichTextBox, type some text and a few new lines(by pressing Enter), enter some more text. Now export the document to a string using TxtFormatProvider then Import it. You will notice that the new lines are missing.
Workaround:
Use the following Import method:
public RadDocument Import(string input)
{
RadDocument document = new RadDocument();
Section section = new Section();
document.Sections.Add(section);
string[] paragraphs = GetParagraphsFromText(input);
for (int i = 0; i < paragraphs.Length; i++)
{
if (string.IsNullOrEmpty(paragraphs[i]))
{
paragraphs[i] = DocumentEnvironment.NewLine;
}
Paragraph paragraph = new Paragraph();
section.Blocks.Add(paragraph);
Span span = new Span(paragraphs[i]);
paragraph.Inlines.Add(span);
}
return document;
}
private string[] GetParagraphsFromText(string input)
{
return this.CleanUpNewLines(input).Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
}
private string CleanUpNewLines(string str)
{
StringBuilder result = new StringBuilder(str.Length);
bool hasSeenCr = false;
for (int i = 0, l = str.Length; i < l; ++i)
{
if (str[i] == '\r')
{
if (hasSeenCr)
{
result.Append(DocumentEnvironment.NewLine);
}
hasSeenCr = true;
}
else if (str[i] == '\n')
{
result.Append(DocumentEnvironment.NewLine);
hasSeenCr = false;
}
else
{
if (hasSeenCr)
{
result.Append(DocumentEnvironment.NewLine);
hasSeenCr = false;
}
result.Append(str[i]);
}
}
if (hasSeenCr)
{
result.Append(DocumentEnvironment.NewLine);
}
return result.ToString();
}
Resolution:
This issue is addressed in the new version of the control - RadRichTextEditor. Please use the new control instead the RadRichTextBox.