// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using System.Collections.Generic; using System.IO; using System.Text; using DotCMIS; using DotCMIS.Client; using DotCMIS.Client.Impl; using DotCMIS.Data; using DotCMIS.Enums; using DotCMIS.Exceptions; namespace CMISDemo.CRUD { public class Program { private static void Dump(ISession ses, string path) { try { Document f = (Document) ses.GetObjectByPath(path); foreach(Property p in f.Properties) { if(p.Value != null) { Console.WriteLine("{0} = {1}", p.LocalName, p.Value); } } IContentStream stm = f.GetContentStream(); StreamReader sr = new StreamReader(stm.Stream); string line; while((line = sr.ReadLine()) != null) { Console.WriteLine(line); } sr.Close(); } catch (CmisObjectNotFoundException) { Console.WriteLine(path + " does not exist"); } } public static void Main(string[] args) { IDictionary param = new Dictionary(); param[SessionParameter.BindingType] = BindingType.AtomPub; param[SessionParameter.AtomPubUrl] = "http://localhost:8080/chemistry/atom"; param[SessionParameter.RepositoryId] = "test"; param[SessionParameter.User] = "test"; param[SessionParameter.Password] = "test"; ISession ses = SessionFactory.NewInstance().CreateSession(param); // read Dump(ses, "/RW/demo.txt"); // create string s = "A\r\nBB\r\nCCC\r\n"; Folder dir = (Folder) ses.GetObjectByPath("/RW"); IDictionary props = new Dictionary(); props[PropertyIds.Name] = "demo.txt"; props[PropertyIds.ObjectTypeId] = "cmis:document"; IContentStream stm = ses.ObjectFactory.CreateContentStream("demo.txt", s.Length, "text/plain", new MemoryStream(Encoding.Default.GetBytes(s))); try { dir.CreateDocument(props, stm, VersioningState.None); } catch(CmisNameConstraintViolationException) { Console.WriteLine("demo.txt did already exist"); } // read Dump(ses, "/RW/demo.txt"); // delete ses.GetObjectByPath("/RW/demo.txt").Delete(true); // read Dump(ses, "/RW/demo.txt"); } } }