SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to know what are benefits/drawbacks when using either of these methods for downloading a document from Sharepoint

using Microsoft sharepoint library

public void Download(string serverFilePath, string destPath) {
    using (FileInformation ffl = Microsoft.SharePoint.Client.File.OpenBinaryDirect(_clientCtx, serverFilePath)) {
        using (Stream destFile = System.IO.File.OpenWrite(destPath)) {
            byte[] buffer = new byte[8 * 1024];
            int len;
            while ((len = ffl.Stream.Read(buffer, 0, buffer.Length)) > 0) {
                destFile.Write(buffer, 0, len);

as oposed to downloading it using WebRequest

public void DownloadFile(string serverFilePath, string destPath) {
    var url = string.Format("{0}/{1}", ServerURL, serverFilePath);
    var request = System.Net.HttpWebRequest.Create(url);
    request.Credentials = _clientCtx.Credentials;
    using (var sr = new StreamReader(request.GetResponse().GetResponseStream())) {
        using (var sw = new StreamWriter(destPath)) {

because using the HttpRequest results in approximately 30% better performance.

Thanks in advance.

share|improve this question

I don't mean to nitpick but your first example is a really bad approach. You are reallocating your buffer every iteration and using a truly tiny buffer at that. Try this approach instead.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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