VCF export

Hello,
The last sample here:

To extract vcf files, is it up to date or you’ve got newer methods implemented?

Dim MyStorage As Email.Storage.Pst.PersonalStorage = Email.Storage.Pst.PersonalStorage.FromFile(OFD.FileName, AsposeLoadOptionsStorage)
Dim MyFolderInfo As Email.Storage.Pst.FolderInfo = MyStorage.RootFolder.GetSubFolder(“Contacts”)
For Each MyMessageInfo As Email.Storage.Pst.MessageInfo In MyFolderInfo.GetContents()
Try
Dim MyContact As Email.Mapi.MapiContact = DirectCast(MyStorage.ExtractMessage(MyMessageInfo).ToMapiMessageItem, Email.Mapi.MapiContact)
MyContact.Save(FBD.SelectedPath + "" + MyContact.NameInfo.DisplayName + “.vcf”, Email.Mapi.ContactSaveFormat.VCard)
Catch Exception As Exception
MsgBox(Exception.Message)
End Try
Next
MyStorage.Dispose()

  1. It throws some exceptions during the loop:
    Unable to cast object of type ‘Aspose.Email.Mapi.MapiDistributionList’ to type ‘Aspose.Email.Mapi.MapiContact’.
    Is it related to the lack of DistList enum as I suggested here?
    StandardIpmFolder
  • I know I can use TryCast and in the next line check if MyContact IsNot Nothing, but I will still get ArgumentNull and NullReference exceptions! I’m attaching my pst so you can test against the provided code.
  1. As I inspected MyStorage after last line of code: MyStorage.Dispose
    Even after disposing, MyStorage still holds the values of these 2 properties: RootFolder and Store!
    .Dispose is just wiping out CanWrite, Format and IsUnicode, but not the above 2 mentioned ones!

So related to number 2, if I run MyStorage.Dispose again and again, it will never throw a null ref exception, since those 2 properties are never wiped out

Aust.Dev.Nerd@outlook.com.zip (761.2 KB)

@australian.dev.nerds

We are investigating this issue and will get back to you soon.

@australian.dev.nerds

We have logged this problem in our issue tracking system as EMAILNET-40713. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@australian.dev.nerds

The contacts folder can contain both contacts and distribution lists. Therefore, to save contacts only, you must check whether the item is a contact. Please check the following code example.

var messageInfoCollection = folderInfo.GetContents();

foreach (MessageInfo messageInfo in messageInfoCollection)
{
    var msgItem = personalStorage.ExtractMessage(messageInfo).ToMapiMessageItem();
    var contact = msgItem as MapiContact;

    if (contact != null)
    {
        contact.Save(contact.NameInfo.DisplayName + ".vcf",
            ContactSaveFormat.VCard);
    }
}

This issue has been fixed in the latest version of Aspose.Email for .NET 22.9.

Hello and thank you very much for your help
The provided sample is exactly what I pasted in the 1st post of this thread (vb.net)

About case 2, already using 22.9 (unless there’s an update to the initial 22.9)

@australian.dev.nerds

Are you still facing exception using latest version of Aspose.Email for .NET 22.9?

Hello,
I’ll get back to it later.
Please kindly advise this line:

Dim MyFolderInfo As Email.Storage.Pst.FolderInfo = MyStorage.RootFolder.GetSubFolder(“Contacts”)

Sometimes it’s null/nothing, does it mean the PST does not have Contacts folder?

And this code can be used to read OST files too? Since reader is the same, just don’t know if OST files can contain contacts?
Thanks.

@australian.dev.nerds

Please share your PST and OST file for investigation. We will investigate the issue and provide you more information on it.

Hello:
sepantasoft@outlook.com.zip (9.9 MB)

@australian.dev.nerds

An investigation ticket has been logged your this case as EMAILNET-40752. You will be informed once there is an update available on it.

@australian.dev.nerds

It is to inform you that the issue which you are facing is actually not a bug in Aspose.Email. So, we have closed this issue (EMAILNET-40752) as ‘Not a Bug’.

  1. If the pst.RootFolder.GetSubFolder("Contacts") method returns null, it means that the root folder doesn’t contain a subfolder named “Contacts”.
  2. If you want to get a folder that contains contacts, use the pst.GetPredefinedFolder(StandardIpmFolder.Contacts) method. For this method, null also means there is no folder.
  3. All of the above applies to both PST and OST.