Creating Objects
To create an object a client has to provide a least the two properties cmis:name and cmis:objectTypeId.
cmis:name sets the name of the object and cmis:objectTypeId sets its object type.
Depending on the object type, more properties can be set or must be set. See also the page about properties.
Creating a Folder
CMIS 1.0 CMIS 1.1 Spec 2.1.5
A folder is always a filed object. That is, you always need a parent folder.
OpenCMIS (Java)
Folder parent = ....
// prepare properties
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, "a new folder");
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
// create the folder
Folder newFolder = parent.createFolder(properties);
PortCMIS (C#)
IFolder parent = ....
// prepare properties
IDictionary<string, object> properties = new Dictionary<string, object>();
properties[PropertyIds.Name] = "a new folder";
properties[PropertyIds.ObjectTypeId] = "cmis:folder";
// create the folder
IFolder newFolder = parent.CreateFolder(properties);
Creating a Document
CMIS 1.0 CMIS 1.1 Spec 2.1.4
Documents can be filed and unfiled. The following samples show how to create a filed document. Use the session object to create an unfiled document.
See also the page about content how to work with content streams.
OpenCMIS (Java)
Folder parent = ....
String textFileName = "test.txt";
// prepare content - a simple text file
String content = "Hello World!";
String filename = textFileName;
String mimetype = "text/plain; charset=UTF-8";
byte[] contentBytes = content.getBytes("UTF-8");
ByteArrayInputStream stream = new ByteArrayInputStream(contentBytes);
ContentStream contentStream = session.getObjectFactory().createContentStream(filename, contentBytes.length, mimetype, stream);
// prepare properties
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, textFileName);
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
// create the document
Document newDoc = parent.createDocument(properties, contentStream, VersioningState.NONE);
PortCMIS (C#)
IFolder parent = ....
string textFileName = "test.txt";
// prepare content - a simple text file
string content = "Hello World!";
string filename = textFileName;
string mimetype = "text/plain; charset=UTF-8";
byte[] contentBytes = Encoding.UTF8.GetBytes(content);
Stream stream = new MemoryStream(contentBytes);
IContentStream contentStream = session.ObjectFactory.CreateContentStream(filename, contentBytes.length, mimetype, stream);
// prepare properties
IDictionary<string, object> properties = new Dictionary<string, object>();
properties[PropertyIds.Name] = textFileName;
properties[PropertyIds.ObjectTypeId] = "cmis:document";
// create the document
IDocument newDoc = parent.CreateDocument(properties, contentStream, VersioningState.None);
Creating a Documet from Source (Copy Content)
OpenCMIS (Java)
Folder folder = ...
Document doc = ...
doc.copy(folder); // create a copy of the document in this folder
PortCMIS (C#)
IFolder folder = ...
IDocument doc = ...
doc.Copy(folder); // create a copy of the document in this folder
Creating a Relationship
CMIS 1.0 CMIS 1.1 Spec 2.1.6
Relationships are always unfiled objects. The ID of the source object and the ID of the target object must be provided. See the page about types how to discover relationship types and their properties.
OpenCMIS (Java)
String sourceId = ...
String targetId = ...
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, "a new relationship");
properties.put(PropertyIds.OBJECT_TYPE_ID, "my:relationsip");
properties.put(PropertyIds.SOURCE_ID, sourceId);
properties.put(PropertyIds.TARGET_ID, targetId);
ObjectId newRelId = session.createRelationship(properties);
PortCMIS (C#)
string sourceId = ...
string targetId = ...
IDictionary<string, object> properties = new Dictionary<string, object>();
properties[PropertyIds.Name] = "a new relationship";
properties[PropertyIds.ObjectTypeId] = "my:relationsip";
properties[PropertyIds.SourceId] = sourceId;
properties[PropertyIds.TargetId] = targetId;
IObjectId newRelId = session.CreateRelationship(properties);
Creating a Policy
CMIS 1.0 CMIS 1.1 Spec 2.1.7
Policies can be filed and unfiled. The following samples show how to create a filed policy. Use the session object to create an unfiled policy.
In most cases it doesn’t make sense to create an policies of the type cmis:policy
because it has no semantics. Usually, the repository provides specific policy types with or without additional properties. See the page about types how to discover policy types and their properties.
OpenCMIS (Java)
Folder parent = ....
// prepare properties
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, "a new policy");
properties.put(PropertyIds.OBJECT_TYPE_ID, "my:policy");
properties.put(PropertyIds.POLICY_TEXT, "my policy description");
// create the policy
Policy newPolicy = parent.createPolicy(properties);
PortCMIS (C#)
IFolder parent = ....
// prepare properties
IDictionary<string, object> properties = new Dictionary<string, object>();
properties[PropertyIds.Name] = "a new policy";
properties[PropertyIds.ObjectTypeId] = "my:policy";
properties[PropertyIds.PolicyText] = "my policy description";
// create the policy
IPolicy newPolicy = parent.CreatePolicy(properties);
Creating an Item
CMIS 1.1 Spec 2.1.8
Items can be filed and unfiled. The following samples show how to create a filed item. Use the session object to create an unfiled item.
In most cases it doesn’t make sense to create an item of the type cmis:item
. Usually, the repository provides specific item types with or without additional properties. See the page about types how to discover item types and their properties.
OpenCMIS (Java)
Folder parent = ....
// prepare properties
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, "a new item");
properties.put(PropertyIds.OBJECT_TYPE_ID, "my:item");
// create the item
Item newItem = parent.createItem(properties);
PortCMIS (C#)
IFolder parent = ....
// prepare properties
IDictionary<string, object> properties = new Dictionary<string, object>();
properties[PropertyIds.Name] = "a new item";
properties[PropertyIds.ObjectTypeId] = "cmis:item";
// create the item
IItem newItem = parent.CreateItem(properties);
Creating object with a Folder Object vs Creating object with the Session Object
OpenCMIS and PortCMIS provide two ways to create objects. The code samples above create objects in a folder. It is also possible to create an object with the session object and without getting the parent folder first.
OpenCMIS (Java)
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
properties.put(PropertyIds.NAME, "a new folder");
ObjectId newFolderId = session.createFolder(properties, parentId);
Both approaches have advantages and disadvantages.
Creating an object with a folder object is more convenient. The create methods return the newly created object.
Creating an object with the session object is faster because it only needs one round-trip to the server. But it only returns the ID of the newly created object.
Unfiled objects can only be created with the session object.