AnsweredAssumed Answered

DotCMIS content update writing first byte only

Question asked by lordzoster on Mar 10, 2014
Latest reply on Mar 11, 2014 by lordzoster
Hallo
I'm trying to update a document content using DotCMIS and C#, but the content is getting the first byte only.
I followed an example I found over the net (here) and matching it with Apache CMIS documentation written in Java (here).
In any way I'm getting a file with the first character only, eg. "T" in the example string.
The only difference I see is the UTF-8 encoding: in my code, the string.toCharArray() method use Unicode encoding.
But at runtime the "file" variable has the correct length (36 bytes) and Alfresco reports the same length for the final document.
With a MIME type of "text/plain" the content has correct length but wrong charset.
Any advice will be greatly appreciated, thanks in advance!

             // fake file
            string fileContent = "This is content for a fake file";
            byte[] file = GetBytes(fileContent);

            // define new document stream object
            ContentStream contentStream = new ContentStream
            {
                FileName = fileName,
                Length = file.Length,             
                MimeType = "application/msword",
                Stream = new MemoryStream( file) 
            };

            Document doc = ((Document)session.GetObjectByPath(parentFolder.Path +"/" + fileName));
               
            doc.UpdateProperties(properties);
            doc.SetContentStream(contentStream, true);
where GetBytes is a custom defined function

static byte[] GetBytes(string str)
        {
            byte[] bytes = new byte[str.Length * sizeof(char)];
            System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
            return bytes;
        }

Outcomes