Title: Getting started with DotCMIS ## Connecting to a CMIS AtomPub endpoint ### Connecting to the first repository :::C# Dictionary parameters = new Dictionary(); parameters[SessionParameter.BindingType] = BindingType.AtomPub; parameters[SessionParameter.AtomPubUrl] = "http:///"; parameters[SessionParameter.User] = ""; parameters[SessionParameter.Password] = ""; SessionFactory factory = SessionFactory.NewInstance(); ISession session = factory.GetRepositories(parameters)[0].CreateSession(); ### Connecting to a specific repository :::C# Dictionary parameters = new Dictionary(); parameters[SessionParameter.BindingType] = BindingType.AtomPub; parameters[SessionParameter.AtomPubUrl] = "http:///"; parameters[SessionParameter.User] = ""; parameters[SessionParameter.Password] = ""; parameters[SessionParameter.RepositoryId] = ""; SessionFactory factory = SessionFactory.NewInstance(); ISession session = factory.CreateSession(parameters); ## Connecting to a CMIS Web Services endpoint ### Connecting to the first repository :::C# Dictionary parameters = new Dictionary(); parameters[SessionParameter.BindingType] = BindingType.WebServices; parameters[SessionParameter.WebServicesRepositoryService] = "http:///"; parameters[SessionParameter.WebServicesAclService] = "http:///"; parameters[SessionParameter.WebServicesDiscoveryService] = "http:///"; parameters[SessionParameter.WebServicesMultifilingService] = "http:///"; parameters[SessionParameter.WebServicesNavigationService] = "http:///"; parameters[SessionParameter.WebServicesObjectService] = "http:///"; parameters[SessionParameter.WebServicesPolicyService] = "http:///"; parameters[SessionParameter.WebServicesRelationshipService] = "http:///"; parameters[SessionParameter.WebServicesVersioningService] = "http:///"; parameters[SessionParameter.User] = ""; parameters[SessionParameter.Password] = ""; SessionFactory factory = SessionFactory.NewInstance(); ISession session = factory.GetRepositories(parameters)[0].CreateSession(); ### Connecting to a specific repository :::C# Dictionary parameters = new Dictionary(); parameters[SessionParameter.BindingType] = BindingType.WebServices; parameters[SessionParameter.WebServicesRepositoryService] = "http:///"; parameters[SessionParameter.WebServicesAclService] = "http:///"; parameters[SessionParameter.WebServicesDiscoveryService] = "http:///"; parameters[SessionParameter.WebServicesMultifilingService] = "http:///"; parameters[SessionParameter.WebServicesNavigationService] = "http:///"; parameters[SessionParameter.WebServicesObjectService] = "http:///"; parameters[SessionParameter.WebServicesPolicyService] = "http:///"; parameters[SessionParameter.WebServicesRelationshipService] = "http:///"; parameters[SessionParameter.WebServicesVersioningService] = "http:///"; parameters[SessionParameter.User] = ""; parameters[SessionParameter.Password] = ""; parameters[SessionParameter.RepositoryId] = ""; SessionFactory factory = SessionFactory.NewInstance(); ISession session = factory.CreateSession(parameters); ## Listing folder children :::C# /// get the root folder IFolder rootFolder = session.GetRootFolder(); // list all children foreach (ICmisObject cmisObject in rootFolder.GetChildren()) { Console.WriteLine(cmisObject.Name); } // get a page IItemEnumerable children = rootFolder.GetChildren(); IItemEnumerable page = children.SkipTo(20).GetPage(10); // children 20 to 30 foreach (ICmisObject cmisObject in page) { Console.WriteLine(cmisObject.Name); } ## Fetching a document :::C# IObjectId id = session.CreateObjectId("12345678"); IDocument doc = session.GetObject(id) as IDocument; // properties Console.WriteLine(doc.Name); Console.WriteLine(doc.GetPropertyValue("my:property")); IProperty myProperty = doc["my:property"]; Console.WriteLine("Id: " + myProperty.Id); Console.WriteLine("Value: " + myProperty.Value); Console.WriteLine("Type: " + myProperty.PropertyType); // content IContentStream contentStream = doc.GetContentStream(); Console.WriteLine("Filename: " + contentStream.FileName); Console.WriteLine("MIME type: " + contentStream.MimeType); Console.WriteLine("Has stream: " + (contentStream.Stream != null)); ## Creating a document :::C# IFolder folder = ... IDictionary properties = new Dictionary(); properties[PropertyIds.Name] = "Hello World Document"; properties[PropertyIds.ObjectTypeId] = "cmis:document"; byte[] content = UTF8Encoding.UTF8.GetBytes("Hello World!"); ContentStream contentStream = new ContentStream(); contentStream.FileName = "hello-world.txt"; contentStream.MimeType = "text/plain"; contentStream.Length = content.Length; contentStream.Stream = new MemoryStream(content); IDocument doc = folder.CreateDocument(properties, contentStream, null); ## Updating properties :::C# ICmisObject cmisObject = ... IDictionary properties = new Dictionary(); properties["my:string"] = "a string"; properties["my:int"] = 42; properties["my:date"] = DateTime.Now; IObjectId newId = cmisObject.UpdateProperties(properties); if (newId.Id == cmisObject.Id) { // the repository updated this object - refresh the object cmisObject.Refresh(); } else { // the repository created a new version - fetch the new version cmisObject = session.GetObject(newId); } ## Deleting an object :::C# IObjectId newId = session.CreateObjectId("12345678"): ICmisObject cmisObject = session.GetObject(newId); cmisObject.Delete(true); ## Performing a query :::C# IItemEnumerable qr = session.Query("SELECT * FROM cmis:document", false); foreach (IQueryResult hit in qr) { Console.WriteLine(hit["cmis:name"].FirstValue + " (" + hit["cmis:objectId"].FirstValue + ")"); }