The app is developed in .NET and reads an RTF document template that contains placeholders that require replacing with text currently stored in a SQL Server database. The app then saves the RTF doc with the substituted text. However, French characters read from the database, such as é are being displayed as é in the RTF document.
The process is:
- read the RTF doc
- replace the placeholders with data from SQL Server db
- save to new RTF doc
The key bits of the code I think are...
Read from RTF doc:
StringBuilder buffer;
using (StreamReader input = new StreamReader(pathToTemplate))
{
buffer = new StringBuilder(input.ReadToEnd());
}
Replace placeholder text with text from database:
buffer.Replace("$$placeholder$$", strFrenchCharsFromDb);
Save the edits as a new RTF doc:
byte[] fileBytes = System.Text.Encoding.UTF8.GetBytes(buffer.ToString());
File.WriteAllBytes(pathToNewRtfDoc, fileBytes);
When I debug buffer during "Save" the é character is present.
When I open the RTF after File.WriteAllBytes it contains é instead.
I have tried specifying the encoding when creating the StreamReader but it was the same result.
i.e. using (StreamReader input = new StreamReader(pathToTemplate, Encoding.UTF8))