首页 > 解决方案 > 在 Outlook C# 中使用比较运算符创建自定义字段过滤器

问题描述

我创建了一个过滤器,它将比较自定义用户属性的值并仅显示满足要求的电子邮件。

过滤器在我有=比较值时起作用,但在我有运算符时不起作用<=

下面是我的过滤器。这行得通。

string filter= $"@SQL=\"http://schemas.microsoft.com/mapi/string/{{00020329-0000-0000-C000-000000000046}}/TimeSpent/0000001f\" = '60'"; 
Outlook.Items restrictedMails = selectedFolder.Items.Restrict(filter);

这行不通。

string filter= $"@SQL=\"http://schemas.microsoft.com/mapi/string/{{00020329-0000-0000-C000-000000000046}}/TimeSpent/0000001f\" <= '60'"; 
Outlook.Items restrictedMails = selectedFolder.Items.Restrict(filter);

在自定义文件中保存值的代码如下。

int duration = (int)completed.Subtract(received).TotalMinutes;
try
                {
                    MailUserProperties = SelectedMail.UserProperties;
                    MailUserProperty = MailUserProperties.Add("TimeSpent", Outlook.OlUserPropertyType.olText, true, 1);
                    MailUserProperty.Value = duration;
                    SelectedMail.Save();
                }

任何人都可以在这里帮助如何让过滤器工作吗?

提前致谢。

标签: outlookvstooutlook-addin

解决方案


 string filter= $"@SQL=\"http://schemas.microsoft.com/mapi/string/{{00020329-0000-0000-C000-000000000046}}/TimeSpent/0000001f\" = '60'";

这里60不是数字,而是字符串。所以,基本上,比较两个字符串。

 MailUserProperty = MailUserProperties.Add("TimeSpent", Outlook.OlUserPropertyType.olText, true, 1);

您添加一个字符串用户属性,然后想要应用一个比较器。只有整数值才有意义。因此,代码应如下所示:

 MailUserProperty = MailUserProperties.Add("TimeSpent", Outlook.OlUserPropertyType.olInteger, true, 1);

只有这样,您才能尝试使用以下过滤器:

 string filter= $"@SQL=\"http://schemas.microsoft.com/mapi/string/{{00020329-0000-0000-C000-000000000046}}/TimeSpent/0000001f\" <= 60";

推荐阅读