API
Version 7.x > API > Stream file from content tree View modes: 
User avatar
Member
Member
david.mavin-sky - 11/25/2013 10:01:35 AM
   
Stream file from content tree
Hi,

Could anyone please advise how I can get a document stream from the content tree. For example we have a simple structure, something like the following.

Content Tree
|_____________Legal
|___________Terms.doc

What set of API's can I use to open the document from the tree and retrieve the stream?

Any advise appreciated.

Cheers
David

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 11/25/2013 10:39:48 AM
   
RE:Stream file from content tree
Hello David,

Could you please be more specific about your idea? What is the purpose of this and what kind of data are you expecting to get?

Best regards,
Martin Danko

User avatar
Member
Member
david.mavin-sky - 11/25/2013 11:56:39 AM
   
RE:Stream file from content tree
Hi,

We are using Aspose automation for Word documents, therefore, we wish to place word document templates in the Kentico content tree (as legal document templates).

Aspose then allows us to manipulate the templates via mail merge and document translation to PDF et.

So we wish to obtain the reference to the template in the content tree and retrieve the raw stream - we can then pass this stream to the component we have created which does all of the mail merge and transformation. Once doe the final document is stored in Azure blob storage.

All of this code is done and working but I need to grab the stream out of the content tree and pass it to this component. This also allows our legal guys to simply upload the document to the content tree.

Any advise on how to get hold of the stream from the content tree (document node id) or whatever would be very helpful.

Cheers
David

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 11/29/2013 9:51:53 AM
   
RE:Stream file from content tree
Hello David,

I'm still not sure what exactly do you imagine under the "stream" but you can try to use our API and search for some helpful method in the API Reference (e.g. DocumentHelper class) or get the data directly from the database table CMS_Document.

Best regards,
Martin Danko

User avatar
Member
Member
david.mavin-sky - 12/1/2013 6:27:36 AM
   
RE:Stream file from content tree
Hi,

Its OK I have sorted it now.

You have to connect to the tree provider, grab the document via the Document Helper class and then use the Attachment Manager to get the attachment and retrieve the stream as binary and re-wind it. I was confused about the fact that a document is also an attachment, but have sorted it now. Also the Document Helper get attachment method does not work so I had to use the attachment manager which did work.

Cheers
David

User avatar
Member
Member
david.mavin-sky - 12/1/2013 6:29:48 AM
   
RE:Stream file from content tree
Hi,

By the way if you wanted the binary stream you via a stored procedure or whatever you cannot use Document entity you have to use the attachment entity. So I guess you could get the information out of the Document entity but would have to go to the attachment entity for the binary. Anyway, I have got the raw binary stream now from the API.

Cheers
David

User avatar
Member
Member
david.mavin-sky - 12/1/2013 6:32:53 AM
   
RE:Stream file from content tree
Hi,

Finally on this, I I am not too sure why you are confused with the term stream? Your API actually has a boolean flag which states "Binary Stream" true or false, e.g retrieve binary stream true or false. At the end of the day a stream is simply an IO or Memory stream of bytes[]?

Cheers
David

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 12/1/2013 9:50:17 AM
   
RE:Stream file from content tree
Hi David,

I just want to clarify the "stream" word in your definition because some users under the "stream" imagine just a content of the page, so just wanted to be sure what exactly are you expecting to receive. But as I see, you know exactly what the stream is :)

Best regards,
Martin Danko