I'm currently trying to create and save an Outlook signature.
The problem is, that it is always saved in a kind of 'default' encoding.
Trying to change this in multiple places to UTF-8 (!) programmatically does not seem to work.
I assume the correct place would only be the change to the WebOptions
as the other encodings are already set to UTF-8 upon inspecting the previous value.
Is there actually a way to change the encoding and also let Outlook save it in that way ?
This is a sample to demonstrate the problem:
using Microsoft.Office.Interop.Word;
using System.Runtime.InteropServices;
namespace CreateSignature
{
class TestCreation
{
static void Main(string[] args)
{
Create();
}
public static void Create()
{
const string _LineBreak = "\v";
string signature = string.Empty;
Application word = new Application();
var document = word.Documents.Add();
var selection = word.Selection;
word.Options.DefaultTextEncoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
document.WebOptions.Encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
selection.Font.Bold = 0;
selection.Font.Name = "Verdana";
selection.Font.Size = 9;
selection.Font.Color = WdColor.wdColorBlack;
selection.TypeText("Best regards");
selection.TypeText(_LineBreak);
selection.TypeText("Special text ### üäöß····· ###");
selection.TypeText(_LineBreak);
document.SaveEncoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
document.Saved = true;
var signatureName = "Test.Signature";
var emailOptions = word.EmailOptions.EmailSignature;
emailOptions.EmailSignatureEntries.Add(signatureName, document.Range());
//emailOptions.NewMessageSignature = signatureName;
//emailOptions.ReplyMessageSignature = signatureName;
word.Quit(WdSaveOptions.wdSaveChanges);
Marshal.ReleaseComObject(word);
}
}
}
The .htm
file will contain this
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
where it should be utf-8
instead of windows-1252
.
It seems to be smiliar to this question, though this is not a loaded document and the suggested change does not work anyway (Fields.Count == 0
).