We use Remote Blob Storage (i.e. SQL FileStream) and SharePoint 2010 to store our files.

We have a web service providing access to parts of SharePoint. One part of this web service includes serving up a stream to download a file stored in our site.

Here's how we currently do it:

    public Stream GetStream(SPFile spFile)
        var memoryStream = new MemoryStream();
        using (var stream = spFile.OpenBinaryStream())
        return memoryStream;

If this is a 500MB file stored in a remote blob, this code copies the whole file to memory first. Run up 10 simultaneous downloads and we're in trouble!

Is there a better way to deliver the FileStream stream without loading it into memory first?


System.IO.Stream should work as it can handle streams of in theory infinite length.

[update] https://stackoverflow.com/questions/437043/best-way-to-handle-a-large-download-site

That's a good read.

  • Stream is an abstract class? I don't understand what you are suggesting – Josh Comley Nov 1 '12 at 16:57
  • Depending on how you exactly want to do it, depends on what you want to use. But the basics are that you create a wrapper that is a manager and a provider. The manager tracks how much data has been requested and the provider loads the chunks and sents them. System.IO.Stream allows for incremental chunks, many examples have been done for file uploads to SharePoint with it. The filestream provides chunks of data to the client, instead of whole files. – Hugh Wood Nov 1 '12 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.