File Net Insert Document

public static void insertDocument(Connection conn, String domainName) {
    // Get domain.
    Domain domain = Factory.Domain.fetchInstance(conn, domainName, null);
    ObjectStoreSet osColl = domain.get_ObjectStores();

    // Get each object store.
    Iterator iterator = osColl.iterator();
    while (iterator.hasNext()) {
        // Get next object store.
        ObjectStore objStore = (ObjectStore) iterator.next();

        // Get the display name of the object store.
        String objStoreName = objStore.get_DisplayName();
        System.out.println("Object store name = " + objStoreName);

        // Create a document instance.
        Document doc = Factory.Document.createInstance(objStore, ClassNames.DOCUMENT);

        // Set document properties.
        doc.getProperties().putValue("DocumentTitle", "New Document via Java API");
        doc.set_MimeType("text/plain"); // if its your pdf then set mimetype for PDF

        doc.save(RefreshMode.NO_REFRESH);

        // Check in the document.
        doc.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
        doc.save(RefreshMode.NO_REFRESH);

        // File the document.
        Folder folder = Factory.Folder.getInstance(objStore, ClassNames.FOLDER, new Id("{42A3FC29-D635-4C37-8C86-84BAC73FFA3F}")); // id of folder to which you want to store document.
        ReferentialContainmentRelationship rcr = folder.file(doc, AutoUniqueName.AUTO_UNIQUE, "New Document via Java API",
                DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE);
        rcr.save(RefreshMode.NO_REFRESH);
    }
}

Comments

Popular posts from this blog

IBM FileNet: Bulk Processing using JavaScript

DB2 Date Time Functions