Web developers wiki ASP.NET Sitecore Sharepoint Kentico by Evident Interactive



When you try to address a stream to read a file, the file appears empty. Just before that, you used Sitecores' CreateFromStream method.



This is caused by the MediaManager.Creator.CreateFromStream method that reads from the stream but doesn't reset the streams' position to 0. The position is left on the last position of the file.

When addressing the stream in another method later on, the stream will be read form the last position and therefor will return an empty file.



Always reset the stream after the use of CreateFromStream:

// Create Media in database from file
Item mediaItem = MediaManager.Creator.CreateFromStream(postedFile.InputStream, fileName, md);

// Reset the stream's position to 0
postedFile.InputStream.Position = 0;

 © Evident Interactive BV