Could not delete all the records from .pst file

Hello


We are using Aspose.Email .Net to delete message from .pst file.
However, we realised that Aspose does not delete all the records from .pst file…due to unknown reason. There is no error thrown by Aspose neither .net. And also, in the logging, the records are repeated for the failed messages…means it holds the value of successful message when the messages are failed.

Our suspicions are that due to some reason, when the records are not deleted, Aspose is not able to keep track of that message until the new message is deleted.

Please see the attached documents for the code.

Really appreciate any help…or whats wrong in the code.

Thanks and Regards

-Josef

Hi Josef,

I tried to reproduce this issue at my end with the following lines of code, but was unable to observe any such issue. It may be that this issue is reproducible with your source PST that we may need to look into. I have used the following lines of code to delete messages from the PST and, with my sample PST, it deleted all messages fine. Please try it with your PST and if the problem persists, please provide us your sample PST so that we can investigate this issue at our end and assist you further.

Private Sub TestDelete()
    Try
        Console.WriteLine("Loading PST file....")
        ' load the Outlook PST file
        Dim pst As PersonalStorage = PersonalStorage.FromFile("outlook.pst")
        ' get the Display Name of the PST file
        Console.WriteLine("Display Name: " + pst.DisplayName)
        ' get the folders and messages information
        Dim folderInfo As FolderInfo = pst.RootFolder
        ' call the recursive method to extract msg files from each folder
        DeleteFromPst(folderInfo, pst)
    Catch ex As Exception
        Console.WriteLine(ex.Message)
        Debug.WriteLine(ex.Message)
    End Try
End Sub

Private Sub DeleteFromPst(ByVal folderInfo As FolderInfo, ByVal pst As PersonalStorage)
    ' display the folder name
    Console.WriteLine("Folder: " & Convert.ToString(folderInfo.DisplayName))
    Console.WriteLine("==================================")
    ' loop through all the messages in this folder
    Dim messageInfoCollection As MessageInfoCollection = folderInfo.GetContents()
    For Each messageInfo As MessageInfo In messageInfoCollection
        Console.WriteLine("Deleting message {0} ....", messageInfo.Subject)
        folderInfo.DeleteChildItem(messageInfo.EntryId)
    Next
    ' call this method recursively for each subfolder
    If folderInfo.HasSubFolders = True Then
        For Each subfolderInfo In folderInfo.GetSubFolders()
            DeleteFromPst(subfolderInfo, pst)
        Next
    End If
End Sub

Hi Kashif


Thanks very much for your response.
Unfortunately the problem still persist.
Please find the attached .pst file (Aspose Email Test - Forum.rar) from which we are trying to delete all the messages, and we are unsuccessful.

Let me know if you need any further information from me.

Thanks and Regards
-Josef

Hi Josef,


I have tried to re-produce the issue using your sample PST with the above mentioned code but could not succeed. I opened the original PST in Outlook and saw 138 messages in INBOX and 129 messages in SENT items folder. I saw the properties of the original PST and it was shown as in attached snap shot.

Above mentioned code was executed with minor modification to print the number of messages deleted. After execution it was observed that all the messages in Inbox, Sent Items and Calendar folder were deleted as shown in the “output.txt” file attached here. Similarly when this processed PST was opened in Outlook its message count was shown zero in Inbox and Sent items folder. Similarly properties of the file are shown in the attached snap shot.

Please give a try again to the following code and send us the log file generated while deleting the messages. Also send us some snap shot where un-deleted messages are visible in the resultant PST. It will help us to identify the problem and assist you as soon as possible.

Private Sub TestDelete()
Try
Console.WriteLine(“Loading PST file…”)
’ load the Outlook PST file
Dim pst As PersonalStorage = PersonalStorage.FromFile(“EMAIL_449060\Aspose Email Test - Forum.pst”)

get the Display Name of the PST file
Console.WriteLine(“Display Name: " + pst.DisplayName)

’ get the folders and messages information
Dim folderInfo As FolderInfo = pst.RootFolder

call the recursive method to extract msg files from each folder
DeleteFromPst(folderInfo, pst)

Catch ex As Exception
Console.WriteLine(ex.Message)
Debug.WriteLine(ex.Message)
End Try
End Sub

Private Sub DeleteFromPst(ByVal folderInfo As FolderInfo, ByVal pst As PersonalStorage)
’ display the folder name
Console.WriteLine(“Folder: " & Convert.ToString(folderInfo.DisplayName))
Console.WriteLine(”==================================”)

loop through all the messages in this folder
Dim messageInfoCollection As MessageInfoCollection = folderInfo.GetContents()

Console.WriteLine("messageInfoCollection.Count = " & messageInfoCollection.Count)
Dim iDeleteCount As Int32 = 0
For Each messageInfo As MessageInfo In messageInfoCollection
Console.WriteLine(“Deleting message {0} …”, messageInfo.Subject)
iDeleteCount = iDeleteCount + 1
folderInfo.DeleteChildItem(messageInfo.EntryId)
Console.WriteLine("Delete Count = " & iDeleteCount)
Next

’ call this method recursively for each subfolder
If folderInfo.HasSubFolders = True Then
For Each subfolderInfo As FolderInfo In folderInfo.GetSubFolders()
DeleteFromPst(subfolderInfo, pst)
Next
End If
End Sub