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) {
CreateDirectoryIfNotExists(Path.GetDirectoryName(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);
CreateDirectoryIfNotExists(Path.GetDirectoryName(destPath));
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)) {
sw.Write(sr.ReadToEnd());
}
}
}
because using the HttpRequest results in approximately 30% better performance.
Thanks in advance.