错误代码:-2147023281,消息:“操作失败";在C#中使用advancedSearch() [英] ErrorCode: -2147023281, Message: "The Operation Failed" in C# using advancedSearch()

查看:142
本文介绍了错误代码:-2147023281,消息:“操作失败";在C#中使用advancedSearch()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

我正在使用

I am using advancedSearch() for filtering my mailbox.

我正在使用上面链接中提到的过滤器:

I was using filter as mentioned in the above link as:

string filterValue = "ticket";

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

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

However, when I try the following:

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

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

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

This throws an exception saying, "This operation failed". Error Code:-2147023281

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

        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)) + @"')";

异常消息是:

操作失败

出了点问题,请重试

推荐答案

我发现了

I discovered this link in Microsoft Docs. In my case, the issue was a folder with a single quote, which was not being properly escaped. Since that folder was being used in the Scope property of the AdvacedSearch method, it was throwing the exception. Maybe it should help you to encounter what is missing in your code.

这篇关于错误代码:-2147023281,消息:“操作失败";在C#中使用advancedSearch()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆