I'm trying to apply auto format rule to Outlook 2016 programmatically. First I've created a rule manually and read the filter property, I've got filter like that:
"(\"urn:schemas:httpmail:read\" = 0 AND \"http://schemas.microsoft.com/mapi/proptag/0x001a001e\" = 'IPM.Note.MyMessage')"
Then I've tried to apply it programmatically:
Dictionary<string, OlColor> colorizationRules = new Dictionary<string, OlColor>()
{
{Resources.MsgClass1, OlColor.olColorRed},
{Resources.MsgClass2, OlColor.olColorYellow},
{Resources.MsgClass3, OlColor.olColorGreen}
};
Explorer explorer = Application.ActiveExplorer();
if (explorer != null)
{
TableView tableView = explorer.CurrentView as TableView;
if (tableView != null)
{
IEnumerable<AutoFormatRule> rules = tableView.AutoFormatRules.Cast<AutoFormatRule>();
foreach (KeyValuePair<string, OlColor> coloriztionRule in colorizationRules)
{
AutoFormatRule newRule = tableView.AutoFormatRules.Add(coloriztionRule.Key);
newRule.Filter = $"(\"urn:schemas:httpmail:read\"=0 AND \"http://schemas.microsoft.com/mapi/proptag/0x001a001e\"='{coloriztionRule.Key}')";
newRule.Font.Color = coloriztionRule.Value;
newRule.Enabled = true;
tableView.AutoFormatRules.Save();
tableView.Save();
tableView.Apply();
}
}
}
Rule is created, but the Filter value is not applied.
One of the suggestions was that Filter value must be prefixed with "@SQL=....". But that does not work.
Then I've found this topic Outlook 2010 AutoFormatRule.Filter property not saving
Where response was:
I raised a premier call in response to this issue. The response was that it is a known bug in the Outlook Object Model. It will not be fixed in Outlook 2010 or Outlook 2013 as the risk is too great for the small change.
And suggested workaround was:
The workaround solution that Microsoft provided was to copy a rule from a Public Folder to the user's profile.
What does that mean? Is there any other workaround to make the rule work from c# code?