本文介绍了EWS - 无法执行此操作,因为一个或多个项目是新的或未修改的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于批次更新问题,我以前曾询问过使用,根据,我可以使用 ExchangeService.UpdateItems p>

所以我修改了:

  Folder.Bind(Service,WellKnownFolderName。收件箱); 

SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And,
new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead,false));

// ItemView将结果限制为numOfMails2Fetch项
FindItemsResults< Item> foundItems = Service.FindItems(WellKnownFolderName.Inbox,sf,
new ItemView(numOfMails2Fetch));

if(foundItems.TotalCount> 0)
{
列表< EmailMessage> emailsList = new List< EmailMessage>(foundItems.TotalCount);

foundItems.Items.ToList()。ForEach(item =>
{
var iEM = item as EmailMessage;
//更新属性BEFORE ADDING
iEM.IsRead = true;

//不要在循环中更新,IE不要使用:
//iEM.Update(ConflictResolutionMode.AutoResolve);

//将EmailMessage添加到列表
emailsList.Add(iEM);
});

//获取每个电子邮件的正文,并将其分配给每个EmailMessage
Service.LoadPropertiesForItems(emailsList,PropertySet.FirstClassProperties);

//批量更新所有电子邮件
ServiceResponseCollection< UpdateItemResponse> response =
Service.UpdateItems(emailsList,
WellKnownFolderName.Inbox,ConflictResolutionMode.AutoResolve,
MessageDisposition.SaveOnly,null);
//上线导致的例外
return emailsList;
}

请注意,我提起了 IsRead 归属,将其添加到列表中。例外情况如下:

从似乎将 IsRead 设置为true应该足够了,为什么这些项目不被考虑批量更新?

解决方案

首先猜测是$ code LoadPropertiesForItems 在外面循环。这可能会通过从服务器返回值来覆盖您的更改。


Relating to a batch update question I asked previously about using a single update to mark as read all the unread emails, I could use ExchangeService.UpdateItems according to Jason's answer.

So I modified accordingly:

Folder.Bind(Service, WellKnownFolderName.Inbox);

SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And,
    new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));

//ItemView limits the results to numOfMails2Fetch items
FindItemsResults<Item> foundItems = Service.FindItems(WellKnownFolderName.Inbox, sf,
    new ItemView(numOfMails2Fetch));

if (foundItems.TotalCount > 0)
{
    List<EmailMessage> emailsList = new List<EmailMessage>(foundItems.TotalCount);

    foundItems.Items.ToList().ForEach(item =>
    {
        var iEM = item as EmailMessage;
        // update properties BEFORE ADDING
        iEM.IsRead = true;

        //DO NOT UPDATE INSIDE THE LOOP,I.E. DO NOT USE:
        //iEM.Update(ConflictResolutionMode.AutoResolve);

        //add the EmailMessage to the list
        emailsList.Add(iEM);
    });

    // fetches the body of each email and assigns it to each EmailMessage
    Service.LoadPropertiesForItems(emailsList,PropertySet.FirstClassProperties);

    // Batch update all the emails
    ServiceResponseCollection<UpdateItemResponse> response =
      Service.UpdateItems(emailsList,
       WellKnownFolderName.Inbox, ConflictResolutionMode.AutoResolve,
       MessageDisposition.SaveOnly, null);
    // ABOVE LINE CAUSES EXCEPTION
    return emailsList;
}

Notice that I pulled up the IsRead attribution, placed it before adding the item to the list. The exception is the following:

From MSDN's example it seems setting IsRead to true should be enough, so why are the items not being considered for the batch update?

解决方案

At first guess it's the LoadPropertiesForItems call you make outside the loop. This likely overwrites your changes by loading the values back from the server.

这篇关于EWS - 无法执行此操作,因为一个或多个项目是新的或未修改的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 12:29