Create DotCMIS IContentStream from local file?

401 Views Asked by At

How to create a DotCMIS.Data.IContentStream object from a local file?

The tutorial only describes how to create one from a byte array in memory:

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);
1

There are 1 best solutions below

0
On

Stream is actually the standard System.IO.Stream of .NET, so here is how to create a DotCMIS IContentStream from a local file:

ContentStream contentStream = new ContentStream();
contentStream.FileName = "hello-world.txt";
contentStream.MimeType = "text/plain";
contentStream.Stream = File.Open("hello-world.txt", FileMode.Open);
contentStream.Length = contentStream.Stream.Length;