【问题标题】:Saving ItemAttachment保存项目附件
【发布时间】:2014-10-02 15:12:46
【问题描述】:

我正在使用 EWS JAVA API 1.2,但使用此代码保存 ItemAttachment 时遇到问题。

if(attachmentsCol.getPropertyAtIndex(i) instanceof FileAttachment) 
{
    ...
}
else
{
    ItemAttachment attachment = (ItemAttachment)attachmentsCol.getPropertyAtIndex(i);                                          
    attachment.load();
    Item item = attachment.getItem();
    item.load(newPropertySet(ItemSchema.MimeContent));`
    MimeContent Itemmc = item.getMimeContent();
    ....
} 

item.load(....) 返回此错误

microsoft.exchange.webservices.data.InvalidOperationException:这 无法执行操作,因为此服务对象没有 一个身份。

感谢您的帮助。

【问题讨论】:

    标签: java exchange-server mime-types ewsjavaapi


    【解决方案1】:

    您不能对 ItemAttachment 本身进行加载,因为这将尝试执行对附件无效的 GetItem 请求。您需要做的是在 Attachment.load() 上包含一个带有 Mime 内容的属性集,例如

                    foreach (var item in findResults.Items)
                    {
                        foreach (Attachment Attach in item.Attachments) {
                            if (Attach is ItemAttachment) {
                                PropertySet psProp = new PropertySet(BasePropertySet.FirstClassProperties);
                                psProp.Add(ItemSchema.MimeContent);
                                ((ItemAttachment)Attach).Load(psProp);
                                if (((ItemAttachment)Attach).Item.MimeContent != null)
                                {
                                    System.IO.File.WriteAllBytes("c:\\temp\\file.eml", ((ItemAttachment)Attach).Item.MimeContent.Content);
                                }                               
                            }
                        }                      
    

    干杯 格伦

    【讨论】:

    • 感谢您的回复...((ItemAttachment)attachment).load(new PropertySet(ItemSchema.MimeContent)); 返回java.lang.ClassCastException: microsoft.exchange.webservices.data.PropertySet cannot be cast to microsoft.exchange.webservices.data.PropertyDefinitionBase 似乎 JAVA API 的行为与 C# 不同。
    • 这可能是 EWS Java 中的一个已知错误。幸运的是,EWS Java 最近是开源的,可以在 Github 上找到:github.com/OfficeDev/ews-java-api 这个特定的错误出现在 ExchangeService.internalGetAttachments(),问题部分的第 12 期。当您通过所有编译器警告在代码中看到它时,您就会知道它。修复应该很快就会在 repo 中,但是如果你看一下,修复自己并不难。
    • 感谢您的两个建议。它解决了我的问题。
    猜你喜欢
    • 2018-12-26
    • 1970-01-01
    • 2016-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多