错误代码:-2147023281,消息:使用AdvancedSearch()在C#中出现“操作失败”

时间:2018-10-20 12:40:13

标签: c# c#-4.0 vsto outlook-addin

背景

我正在使用advancedSearch()来过滤我的邮箱。

我在上面的链接中使用的过滤器是:

string filterValue = "ticket";

string filter = "urn:schemas:mailheader:subject LIKE \'%" + filterValue + "%\'";

但是,当我尝试以下操作时:

DateTime startTime = new DateTime(2018, 9, 23, 16, 48, 0);

string filter = @"@SQL=(""urn:schemas:httpmail:date"" >= '" + startTime.ToString("g") + @"')";`

这将引发异常,指出“此操作失败”。错误代码:-2147023281

screenshot

我还尝试了什么(但是所有这些都抛出异常并且不起作用):-

        Outlook.PropertyAccessor pa = folder.PropertyAccessor;
        DateTime datStartUTC = pa.LocalTimeToUTC(Convert.ToDateTime("10/19/2018"));
        DateTime datEndUTC = pa.LocalTimeToUTC(Convert.ToDateTime("10/26/2018").AddDays(1));
        DateTime startTime = new DateTime(2018, 9, 23, 16, 48, 0);
        DateTime endTime = new DateTime(2018, 9, 26, 12, 00, 0);

        string filter = @"@SQL=((""urn:schemas:httpmail:datereceived"" >= '" + datStartUTC + @"' AND ""urn:schemas:httpmail:datereceived"" <='" + datEndUTC + @"' ))";
        string filter = @"@SQL =((""urn:schemas:httpmail:date"" >= '" + datStartUTC + @"' AND ""urn:schemas:httpmail:date"" <='" + datEndUTC + @"' ))";         
        string filter = ("http://schemas.microsoft.com/mapi/proptag/0x0E060040 >  /' startTime /' ");
        string filter = "[Start] >= '" + startTime.ToString("g") + "' AND [End] <= '" + endTime.ToString("g") + "'";
        string filter = "urn:schemas:httpmail:datereceived LIKE \'%" + pa.LocalTimeToUTC(DateTime.Now).ToString("g") + "%\'";
        string filter = "urn:schemas:httpmail:datereceived LIKE \'%" + pa.LocalTimeToUTC(DateTime.Now) + "%\'";
        string filter = "urn:schemas:httpmail:datereceived LIKE \'%" + (DateTime.Now - new TimeSpan(7, 0, 0, 0)).ToString("g") + "%\'";
        string filter = "urn:schemas:httpmail:datereceived"" <= '" + (DateTime.Now - new TimeSpan(7, 0, 0, 0)).ToString("g") + @"');
        string filter = "urn:schemas:httpmail:datereceived LIKE \'%" + startTime + "%\'";
        string filter = @"@SQL=(""urn:schemas:httpmail:datereceived"" >= '" + (DateTime.Now - new TimeSpan(7, 0, 0, 0)) + @"')";

异常消息是:

  

操作失败

     

     

出了点问题,请重试

1 个答案:

答案 0 :(得分:0)

我在Microsoft文档中发现了this链接。就我而言,问题是一个带单引号的文件夹,但没有正确转义。由于该文件夹已在AdvacedSearch方法的Scope属性中使用,因此引发了异常。也许它应该可以帮助您解决代码中缺少的内容。