【问题标题】:Exchange EWS MailItem shows attachment but doesn't let me retrieve the fileattachmentExchange EWS MailItem 显示附件,但不允许我检索文件附件
【发布时间】:2017-08-02 00:27:09
【问题描述】:

我正在尝试从交换电子邮件中加载文件附件(其图像文件)。

` foreach(findResults.Items 中的 EmailMessage 项) { if (item.HasAttachments) { var something = item.Attachments[0];

                foreach (Attachment attachment in item.Attachments)
                {
                    if (attachment is FileAttachment)
                    {
                        FileAttachment fattach = (FileAttachment)attachment;`

由于某种原因,即使该项目有附件(我可以通过登录网络界面来确认),它也不允许我检索文件附件。

它显示为空。为什么某个项目在集合中有附件但无法检索?

【问题讨论】:

    标签: exchangewebservices


    【解决方案1】:

    我遇到了一个类似的问题,没有设置所有属性,因此您需要从 Exchange 服务本身调用 LoadPropertiesForItems 方法来加载附件等额外数据。
    例如,如果您要加载项目 x 的所有附件并且交换服务实例是 s 那么:

    List<Item> xlist = new List<Item>();
                xlist.Add(x);
                s.LoadPropertiesForItems(xlist,PropertySet.FirstClassProperties);
    

    【讨论】:

      【解决方案2】:

      绑定Item时,需要指定Attachments属性。以下代码示例应该会有所帮助:

      PropertySet propertySet = new PropertySet(ItemSchema.Subject, ItemSchema.Attachments);    
      Item item = Item.Bind(service, itemId, propertySet);
      

      【讨论】:

        【解决方案3】:

        您错过了加载附件。请参阅下面的示例以获取想法

        EmailMessage msgInfo = null;
        foreach (Item msgItemInfo in msgItemWithNotification)
        {
           msgInfo = EmailMessage.Bind(exchange, msgItemInfo.Id);
           foreach (Attachment attachment in msgInfo.Attachments)
               {
                   if( attachment is FileAttachment)
                      {
                          FileAttachment fattach = attachment as MSEWS.FileAttachment;
                          fattach.Load();
                          Stream excelFileStream = new System.IO.MemoryStream(fattach.Content);
                      }
               }
        }
        

        【讨论】:

          猜你喜欢
          • 2012-06-21
          • 2011-07-03
          • 2019-05-17
          • 2017-03-15
          • 2023-03-06
          • 1970-01-01
          • 2014-03-04
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多