I'm working with a RTF-template. In this template there are a few places where text need to be replaced. This works fine, when using ASCII chars. When I use non-ASCII chars, the chars changes to question marks.
My program code:
memo = memo.Replace("%TITEL%", titel);
memo is the RTF file, which is readed in my code as a string. %TITEL%
exists in the RTF-template en titel
has the following text:
Förderband
So %TITEL%
is replaces by Förderband
.
When I open the document, word shows:
F?rderband
I add the RTF-string to a Word document with the following:
// Read RTF document content.
string rtfDocumentContent = memo;
using (MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(rtfDocumentContent)))
{
chunk.FeedData(ms);
}
AltChunk altChunk = new AltChunk();
altChunk.Id = altChunkId;
// Embed AltChunk after the last paragraph.
mainDocPart.Document.Body.InsertAfter(
altChunk, mainDocPart.Document.Body.Elements<DocumentFormat.OpenXml.Wordprocessing.Paragraph>().Last());
Can anyone help me?