I'm using TextWriter to make a RTF file based on a string.
TextWriter tw = new StreamWriter(@"C:\test\test.rtf",false,Encoding.GetEncoding("iso-8859-1"));
tw.Write(text);
Beneath is the string I feed to TextWriter
. I built it using
String.Concat<T>(IEnumerable<T>)
The values in that collection have been turned into RTF by Xceed.Wpf.Toolkit.RichTextBox
"{\\rtf1\\ansi\\ansicpg1252\\uc1\\htmautsp\\deff2{\\fonttbl{\\f0\\fcharset0 Times New Roman;}{\\f2\\fcharset0 Segoe UI;}}{\\colortbl\
\red0\\green0\\blue0;\\red255\\green255\\blue255;}\\loch\\hich\\dbch\\pard\\plain\\ltrpar\\itap0{\\lang1033\\fs24\\f2\\cf0 \\cf0\\ql{\
\f2 {\\b\\ltrch test.}\\li0\\ri0\\sa0\\sb0\\fi0\\ql\\par}\r\n{\\f2 {\\b\\ltrch (test, test, test, test)}\\li0\\ri0\\sa0\\sb0\\fi0\\ql\
\par}\r\n{\\f2 \\li0\\ri0\\sa0\\sb0\\fi0\\ql\\par}\r\n{\\f2 {\\ltrch test: test}\\li0\\ri0\\sa0\\sb0\\fi0\\ql\\par}\r\n}\r\n}{\\rtf1\
\ansi\\ansicpg1252\\uc1\\htmautsp\\deff2{\\fonttbl{\\f0\\fcharset0 Times New Roman;}{\\f2\\fcharset0 Segoe UI;}}{\\colortbl\\red0\
\green0\\blue0;\\red255\\green255\\blue255;}\\loch\\hich\\dbch\\pard\\plain\\ltrpar\\itap0{\\lang1033\\fs24\\f2\\cf0 \\cf0\\ql{\\f2 {\
\b\\ltrch test.}\\li0\\ri0\\sa0\\sb0\\fi0\\ql\\par}\r\n{\\f2 {\\b\\ltrch (test, test, test, test)}\\li0\\ri0\\sa0\\sb0\\fi0\\ql\\par}\r
\n{\\f2 \\li0\\ri0\\sa0\\sb0\\fi0\\ql\\par}\r\n{\\f2 {\\ltrch test: test}\\li0\\ri0\\sa0\\sb0\\fi0\\ql\\par}\r\n}\r\n}"
This is the RTF file:
{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl
\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs24\f2\cf0 \cf0\ql{\f2 {\b\ltrch
test.}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 {\b\ltrch (test, test, test, test)}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 \li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 {\ltrch test: test}\li0\ri0\sa0\sb0\fi0\ql\par}
}
}{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl
\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs24\f2\cf0 \cf0\ql{\f2 {\b\ltrch
test.}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 {\b\ltrch (test, test, test, test)}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 \li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 {\ltrch test: test}\li0\ri0\sa0\sb0\fi0\ql\par}
}
}
It opens fine in Notepad.
But I have to remove 2 curly braces (the }{
just before the 2nd rtf1
tag) to get MS Word to display the whole file:
{\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl
\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs24\f2\cf0 \cf0\ql{\f2 {\b\ltrch
test.}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 {\b\ltrch (test, test, test, test)}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 \li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 {\ltrch test: test}\li0\ri0\sa0\sb0\fi0\ql\par}
}
\rtf1\ansi\ansicpg1252\uc1\htmautsp\deff2{\fonttbl{\f0\fcharset0 Times New Roman;}{\f2\fcharset0 Segoe UI;}}{\colortbl
\red0\green0\blue0;\red255\green255\blue255;}\loch\hich\dbch\pard\plain\ltrpar\itap0{\lang1033\fs24\f2\cf0 \cf0\ql{\f2 {\b\ltrch
test.}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 {\b\ltrch (test, test, test, test)}\li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 \li0\ri0\sa0\sb0\fi0\ql\par}
{\f2 {\ltrch test: test}\li0\ri0\sa0\sb0\fi0\ql\par}
}
}
Untill i remove those braces, Word shows only the first record:
test.
(test, test, test, test)
test: test
instead of the whole document:
test.
(test, test, test, test)
test: test
test.
(test, test, test, test)
test: test
I've tried to google a solution, to no avail. Any help would be appreciated.