Moyosoft Products | Services | Download | Contact us    
Java Outlook Connector
Products  >  Java Outlook Connector  >  API Reference    
API Reference
   
Overview  |  
Classic JavaDoc

Outlook.addStore

public void addStore(java.io.File storePstFile)

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:
storePstFile   the PST file to be loaded

See Also:

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:
storePstFile   the PST file to be loaded
type   the type of the store: StoreType.DEFAULT, StoreType.UNICODE or StoreType.ANSI

See Also:

Community comments


Find the folder where the store was loaded
Vote up  |  Vote down
    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;
    }


Powered by JavaDocPlus