Free Support Forum -

How to know if a directory exists in a pst file

I would like to know if a directory exists in a pst file to know if I should create it.
the code is :
FolderInfoLoc = PstExport.RootFolder.GetSubFolder(“Contact”)
if “Contact” directory does not exist what is the return value ? “Nothing” does not work ?

The test would be:
if FolderInfoLoc=Nothing then 'PROBLEM
'Create th folder
FolderPST=Pst.CreatePredefinedFolder(“Contacts”, StandardIpmFolder.Contacts)
'Add the message

'or in a subfolder
'Add the message to the subfolder

end if

This code does not work. Why ?

thanks for your help


Hi Marc,

Thank you for using Aspose.Email.

It seems you are getting error at the line:

If FolderInfoLoc = Nothing Then

Please have a look at the following lines of code for your kind reference. It opens a PST file and checks for the existence of a folder. If it doesn't exist, then it creates this folder in the PST. Please let us know your feedback if this doesn't solve your issue.

Dim pst As PersonalStorage = PersonalStorage.FromFile("Test1.pst")

Dim folder As FolderInfo = pst.RootFolder.GetSubFolder("Contacts")

If folder Is Nothing Then

pst.CreatePredefinedFolder("Contacts", StandardIpmFolder.Contacts)

End If