Hello,
Having hard times to write the olm to pst, to reflect the source olm folders in written pst.
2 folders will throw InvalidOperationException: JunkEmail and SyncIssues
Dim DestFolder As Pst.FolderInfo = Nothing
Select Case OlmFolder.Name.ToLower
Case "junk email"
DestFolder = OutputStorage.GetPredefinedFolder(StandardIpmFolder.JunkEmail)
If DestFolder Is Nothing Then DestFolder = OutputStorage.CreatePredefinedFolder(OlmFolder.Name, StandardIpmFolder.JunkEmail, True)
Case "sync issues"
DestFolder = OutputStorage.GetPredefinedFolder(StandardIpmFolder.SyncIssues)
If DestFolder Is Nothing Then DestFolder = OutputStorage.CreatePredefinedFolder(OlmFolder.Name, StandardIpmFolder.SyncIssues, True)
End Select
DestFolder.AddMessage...
If GetPredefinedFolder does not find the folder, it should return nothing, then I use CreatePredefinedFolder
The problem is that for 2 folders, GetPredefinedFolder returns nothing while it exists and hence CreatePredefinedFolder returns:
Failed to create the folder. The folder with same name already exists.
Is this a bug? It only seems to happen for multi account olm files whith multiple accounts under Accounts.…
Or my code is not correct? Thanks 
@australian.dev.nerds
It appears you are facing an issue with the GetPredefinedFolder method returning Nothing for the “Junk Email” and “Sync Issues” folders, despite their existence in the OLM file. This can cause the CreatePredefinedFolder method to fail, as it may detect that a folder with the same name already exists.
This behavior may be influenced by the structure of multi-account OLM files. Here are some suggestions to troubleshoot and potentially resolve the issue:
-
Check Folder Existence: Before invoking CreatePredefinedFolder, verify whether the folder actually exists in the PST. You can iterate through the existing folders in the PST to confirm their presence.
-
Use Try-Catch: Enclose your folder creation logic in a try-catch block to gracefully handle the InvalidOperationException. This allows you to skip the creation step if the folder already exists.
-
Debugging: Implement logging to capture the exact names and paths of the folders being processed. This can help identify any discrepancies in naming or structure.
Here’s a revised version of your code snippet that includes a try-catch block:
Dim DestFolder As Pst.FolderInfo = Nothing
Select Case OlmFolder.Name.ToLower
Case "junk email"
DestFolder = OutputStorage.GetPredefinedFolder(StandardIpmFolder.JunkEmail)
Case "sync issues"
DestFolder = OutputStorage.GetPredefinedFolder(StandardIpmFolder.SyncIssues)
End Select
If DestFolder Is Nothing Then
Try
DestFolder = OutputStorage.CreatePredefinedFolder(OlmFolder.Name, StandardIpmFolder.JunkEmail, True)
Catch ex As InvalidOperationException
' Handle the case where the folder already exists
' Optionally log the exception or take other actions
End Try
End If
' Proceed to add messages to DestFolder
If DestFolder IsNot Nothing Then
DestFolder.AddMessage(...)
End If
If the issue continues, consider reaching out to Aspose support with detailed information about your OLM file structure and the specific error messages you are encountering.
1 Like
Yes, I’m doing the same! One thing with olm is that it may contain 2 separate folders “Deleted Items” and “Trash” which seems the same, plus “Junk Email” and “Junk E-mail”, seems same function too 
It looks like the issue is with the structure of the target PST. In your PST, the folders Junk Email and Sync Issues are not defined as predefined folders, but rather as regular ones. That’s why GetPredefinedFolder returns Nothing. Since the folder with the same name already exists (as a normal folder), CreatePredefinedFolder also fails with the exception.
So it’s not a bug; it’s just that in this particular PST, these folders are not recognized as standard folders.
1 Like