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

migrated from Mar 7 '13 at 13:35

This question came from our site for professional and enthusiast programmers.

up vote 5 down vote accepted

Do you want fries metadata with your file? Use the SharePoint Library.

Only interested in the binary stream of the file? Use the framework code (WebRequest).

share|improve this answer

On top of better performance, one wants to consider what can be most easily read and explained. If you are working on a team, does that team have more familiarity with the SharePoint Library or the WebRequest. Lastly, which of the code snippets could be more module and used in other classes and projects? Taking all of these into consideration will help you determine what is the "best" code.

Hope this helps!

share|improve this answer
thank you for your reply. maybe I should have been more clear with my question, i there any specific difference when using Sharepoint method for getting the stream as opposed to just simply getting it through a simple web request. – Miran Mar 7 '13 at 13:27

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.