在处理 C# Outlook 之前按接收时间对电子邮件进行排序
在处理电子邮件并将数据输入数据库时,我需要先按接收时间对电子邮件进行排序。
我需要它,以便将收到的最新电子邮件放入数据库中以覆盖旧版本(如果有旧版本)。
Microsoft.Office.Interop.Outlook.Items 项目 = (Outlook.Items)source.Items;
源是包含我想要排序的电子邮件的文件夹
我已经尝试了以下四种方法:
items.Sort("ReceivedTime", false);
items.Sort("[ReceivedTime]", Outlook.OlSortOrder.olAscending);
items.Sort("ReceivedTime", Outlook.OlSortOrder.olSortNone);
items.Sort("[ReceivedTime]");
这似乎没有对它进行排序,因为它仍然将最旧的邮件放入第二个数据库中,覆盖最新的提交。
有什么想法吗?
I need to sort my emails by Received time before processing them as I am processing emails and entering data from it into a database.
I need it so the newest email to be received gets put into the database to overwrite the older version (If there is an older version).
Microsoft.Office.Interop.Outlook.Items item = (Outlook.Items)source.Items;
Source is the folder with the emails in it that I wanted sorted
I have tried these four ways:
items.Sort("ReceivedTime", false);
items.Sort("[ReceivedTime]", Outlook.OlSortOrder.olAscending);
items.Sort("ReceivedTime", Outlook.OlSortOrder.olSortNone);
items.Sort("[ReceivedTime]");
Which does not seem to sort it as It still puts the oldest into the database second, overwriting the newest submission.
Any Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果你希望它们降序,它应该是
或
true
it should be
or
true
if you want them descending我花了很多时间试图解决同样的问题。
Microsoft Interop.outlook 中似乎存在某种错误,如果您直接尝试从文件夹中排序,它根本不起作用。
I spent so much time trying to figure out the same problem.
It appears there is some sort of bug in Microsoft Interop.outlook that if you directly try to sort from folder it does not work at all.
现在我不知道你的项目对象是什么类,但也许“排序”方法没有返回类型“void”,但它本身返回一个新列表。
因此,您应该像这样分配您的列表:
然后您可以尝试四种方法中的哪一种适合您的需求。
我希望这有帮助!
Now I don't know what class your item-Object is, but maybe the "Sort"-Method does not have return type "void", but it returns a new list itself.
So you should assign your list like so:
You could then try, which of your four approaches fits your needs.
I hope this helps!
这段代码来自MSDN。我很困惑为什么一开始它就设置了
myItmes=myFolder.Items
。经过多次尝试,我知道这是一个陷阱。如果直接使用myFolder.Items.sort
...,排序功能不起作用。This code is come from MSDN. I am confused as to why at beginning it sets
myItmes=myFolder.Items
. After trying many times, I know this is a trap. If you usemyFolder.Items.sort
... directly, the sort function does not work.