Deliver superior customer experiences with an AI-driven platform for creating and deploying cognitive chatbots
Deliver Awesome UI with the most complete toolboxes for .NET, Web and Mobile development
Automate UI, load and performance testing for web, desktop and mobile
A complete cloud platform for an app or your entire digital business
Detect and predict anomalies by automating machine learning to achieve higher asset uptime and maximized yield
Automate decision processes with a no-code business rules engine
Optimize data integration with high-performance connectivity
Connect to any cloud or on-premises data source using a standard interface
Build engaging multi-channel web and digital experiences with intuitive web content management
Personalize and optimize the customer experience across digital touchpoints
Build, protect and deploy apps across any platform and mobile device
Rapidly develop, manage and deploy business apps, delivered as SaaS in the cloud
The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
I described why Streaming API was needed in Sitefinity, and then I covered on the new API and the changes that were necessary to support it. Now, I am going to show you how to use it.
Creating the item (IContent) is done via the manager. However, we don't set the IContent.Content property manually. We, instead, use the Sreaming API to retrieve an upload stream (overriding any previous content that was there) and "upload" our content. Here is a short example:
// let us say we want to upload a file from App_Data
var data = File.OpenRead(HttpContext.Current.Server.MapPath(
// retrieve the default provider
ContentManager manager =
// craete an IContent as you would normally do
var content = (IStreamableContent)manager.CreateContent(
// the content must be retrievable by ID for streaming to work
// so we save it first and then get it back into transaction
content = (IStreamableContent)manager.GetContent(content.ID);
// retrieve an upload stream. Be sure to check if the streaming provider is null.
&& content !=
// don't forget to call dispose, as otherwize the data may be corrupted
// to be save, wrap in using statement
(var contentStream = manager.StreamingProvider.GetUploadStream(content))
// optimize chunk size by passing the active provider as last argument
// we could manually set the the chunk size, of course
// StreamHelper.CopyStream(data, contentStream, false, 1024L);
// finally, we save. Note, that, the binary content is already saved to database
// this call should not be necessary
For the example to work, it is assumed that you have reference to Telerik.Cms.Engine.dll and you have at least System, System.IO, Telerik.Cms.Engine and Telerik.Cms.Engine.Streaming namespaces included with the using statement.
This will work only if the content has been uploaded with an UploadStream
// for this example, we will assume that
// content is IStreamableContent and manager is ContentManager
// here is another way to retrieve the streaming provider
// this will be the streaming provider used initially to upload the content
// assuming we want to save the data to a file
(var fileStream = File.OpenWrite(@
(var contentStream = content.StreamingProvider.GetDownloadStream(content))
// we will use the default buffer (chunk) size, which is 1MB
// and yet another way to retrieve the streaming provider
// do the actual deletion
// this will delete the binary content only and not the IContent itself.
// deleting the IContent will delete its binary data as well, by calling
// this same method. Since it is virtual, this is the place you will want to
// do your deletion logic if you do your custom streaming provider
There is no update in the strict sense of the word. You would exactly the same thing as with creating - retrieve an upload stream and write your binary data. The upload stream doesn't support seeking, so you won't be able to set the Position either. You can't have an upload and download stream at the same time, as well, since data is flushed once a chunk/buffer is discarded. This is made so because the goal of streaming is to keep as little of the actual data in memory as possible.
Put in an example, here is what you would to to "update" via streaming:
// content is assumed to be IStreamableContent and manager is assumed to be ContentManager
// Getting the upload stream itself will delete the existing content,
// even if you don't write anything
(var data = File.OpenRead(@
(var uploadStream = manager.StreamingProvider.GetUploadStream(content))
Although this defeats the idea of streaming, you can do this if you know beforehand that the binary data is small.
// content is IContent and manager is ContentManager
// this is another way to do streaming
(var source = streamingProvider.GetDownloadStream((IStreamableContent)content))
// don't load in memory unless you have a good reason to do so
// ReadToEnd will read any Stream in memory
 binaryDataInMemory = StreamHelper.ReadToEnd(source,
// do something with the binary Data
// for this example, you will need a reference to Telerik.Libraries.dll. It is assumed you have
// using for Telerik.Libraries. libManager is an instance of LibraryManager and ILibrary is an
// instance of the library you want to upload to
// retrieve a source stream to upload
(var source = File.OpenRead(@
// use the familiar UploadFile in LibraryManager
var uploadedContent =
// it will return an instance of the created IContent item
// first argument is the source stream. It should support setting the Position property.
// file name
// file extension
// mime type
// library to upload the file to
Even though I use StreamHelper to copy and read streams, it is not necessary. You can read/write to streams manually if you want to, but I do not recommend it. For one, it will save you time, and it is optimized.
In my next blog post, I will explain the corner cases in which the binary data is loaded in memory even when streaming is used.
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Copyright © 2018 Progress Software Corporation and/or its subsidiaries or affiliates.
All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.