0

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?

Pim_D
  • 89
  • 1
  • 10

1 Answers1

0

You are using ASCII encoding. Perhaps you should change to UTF-8 using the following code block

using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(rtfDocumentContent)))
{
    chunk.FeedData(ms);
}

Hope this helps

MarcoLaser
  • 266
  • 1
  • 5