1

我目前正在开发一个 Outlook 加载项,它可以将 MailItems 和附件保存到 SQL 数据库中。

保存带有附件的 MailItem 时,MailItem 中添加了 2 个类别,表示消息已保存并且附件已保存。

添加只有 1 个附件的 MailItem 时,类别会正确添加,如下所示。正确的

但是当我保存带有 2 个或更多附件的 MailItem 时,它看起来像这样: 错误的

这是添加类别的代码:

foreach (Outlook.Attachment att in mailItem.Attachments)
{
    try
    {
        att.SaveAsFile(Path.GetTempPath() + att.FileName);

        var fi = new FileInfo(Path.GetTempPath() + att.FileName);

        var attachment = Attachment.NieuwAttachment(att.FileName,
                                                    SelectedMap.DossierNr.ToString(
                                                        CultureInfo.InvariantCulture), -1,
                                                    Convert.ToInt32(SelectedMap.Tag), fi);
        if (!Attachment.InlezenAttachment(attachment)) continue;

        //if attachment is being saved add "attachment saved" category to mailitem
        mailItem.Categories = string.Format("{0}, {1}", OutlookCategories.CategorieBijlage, mailItem.Categories);
        mailItem.Save();
    }
    catch (Exception ex)
    {
        var dmsEx = new DmsException("Er is een fout opgetreden bij het opslaan van een bijlage.",
                                     ex.Message, ex);
        ExceptionLogger.LogError(dmsEx);
    }
}

任何人都可以帮我解决这个问题???

4

1 回答 1

2

What you should do is add a check to see if the category already exists:

use this:

if (!mailItem.Categories.Contains(OutlookCategories.CategorieBijlage))
{
     //if attachment is being saved add "attachment saved" category to mailitem
     mailItem.Categories = string.Format("{0}, {1}", OutlookCategories.CategorieBijlage, mailItem.Categories);
     //Opslaan van MailItem.
     mailItem.Save();
}
于 2013-12-06T11:42:18.607 回答