We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Avoid to add duplicate items in folder of a pst file

How can i avoid to add duplicates mail in a folder of a pst file?

@alibardisk,

Thank you for contacting Aspose Support.

You may use the code snippet given below to check if an email already exists in the PST file.

MapiMessage mapiMessage = MapiMessage.FromFile(MessageToBeAdded);
using (PersonalStorage pst = PersonalStorage.FromFile(PstFile))
{
    FolderInfo folderInfo = pst.RootFolder.GetSubFolder("Inbox");
    if(!MessageExists(pst, folderInfo, mapiMessage.InternetMessageId))
    {
        folderInfo.AddMessage(mapiMessage);
    }
}

public static bool MessageExists(PersonalStorage pst, FolderInfo folderInfo, string internetMessageId)
{
    bool MessageExists = false;
    foreach (MessageInfo message in folderInfo.EnumerateMessages())
    {
        MapiProperty MessageId = pst.ExtractProperty(
        message.EntryId, MapiPropertyTag.PR_INTERNET_MESSAGE_ID_W);
        if (MessageId.ToString() == internetMessageId)
        {
            MessageExists = true;
            break;
        }
    }
    return MessageExists;
}

We hope that this answered your question. Please feel free to reach us if additional information is required.