public static void main(String[] args) throws ComponentObjectModelException, LibraryNotFoundException
{
Outlook outlook = new Outlook();
try
{
// Load the store (.pst file)
OutlookFolder storeFolder = addStore(outlook, new File("c:\\test.pst"));
if(storeFolder != null)
{
System.out.println("Folders stored in the file: ");
FoldersIterator folders = storeFolder.getFolders().iterator();
while(folders.hasNext())
{
OutlookFolder folder = (OutlookFolder) folders.next();
System.out.println("Folder name: " + folder.getName());
}
// Unload and remove the store from Outlook
outlook.removeStore(storeFolder);
}
}
finally
{
outlook.dispose();
}
}
private static OutlookFolder addStore(Outlook outlook, File storeFile)
{
ArrayList listFolderIds = new ArrayList();
for(FoldersIterator iterator = outlook.getFolders().iterator(); iterator.hasNext();)
{
OutlookFolder folder = (OutlookFolder) iterator.next();
OutlookFolderID folderId = folder.getFolderId();
if(folderId != null)
{
listFolderIds.add(folderId);
}
}
outlook.addStore(storeFile);
for(FoldersIterator iterator = outlook.getFolders().iterator(); iterator.hasNext();)
{
OutlookFolder folder = (OutlookFolder) iterator.next();
OutlookFolderID folderId = folder.getFolderId();
if(folderId != null)
{
if(!listFolderIds.contains(folderId))
{
return folder;
}
}
}
return null;
}
API Reference
| Classic JavaDoc |
Outlook.addStore
public void addStore(java.io.File storePstFile)
public void addStore(java.io.File storePstFile, StoreType type)
Opens the specified PST file in a new Outlook folder. To remove
the added folder, use the method removeStore.
If the specified file doesn't exist, a new PST file will be created.Parameters:
See Also:
storePstFile | the PST file to be loaded |
public void addStore(java.io.File storePstFile, StoreType type)
Opens the specified PST file in a new Outlook folder. To remove
the added folder, use the method removeStore.
If the specified file doesn't exist, a new PST file will be created using the
specified store type.Parameters:
See Also:
storePstFile | the PST file to be loaded |
type | the type of the store: StoreType.DEFAULT, StoreType.UNICODE or StoreType.ANSI |
Community comments
Powered by JavaDocPlus