Reputation: 50
I am using the below command to delete emails from PST.
foreach (Redemption.RDOMail oitem in filteredItems)
{
try
{
oitem.Delete();
}
catch (Exception ex)
{
PSTLog.Log("Exception in DeleteEmails: " + ex.Message);
}
}
The Redemption DLLs indicate the emails have been deleted successfully. If I try to read PST again using Redemption DLLs, I get lower email count which makes sense. However, I am still able to see the deleted emails in Outlook. Tried options like closing/reopening Outlook & detaching/re-attaching PST in Outlook, but it has not helped.
Is it possible Outlook is caching the results elsewhere and causing this discrepancy? Outlook version is 2016.
Any help would be appreciated!!
Upvotes: 0
Views: 77
Reputation: 66286
Do not use foreach
loops if you are modifying the collection. Use a down "for
" loop:
foreach ( int i = filteredItems.Count; i > 0; i--)
{
Redemption.RDOMail oitem = filteredItems[i];
try
{
oitem.Delete();
}
catch (Exception ex)
{
PSTLog.Log("Exception in DeleteEmails: " + ex.Message);
}
Marshal.ReleaseComObject(oitem);
}
Upvotes: 0