Help appreciated in resolving the 'Out of memory exception' from the below source at line return Convert.ToBase64String(stream.ToArray())
;
private static string GetSPFileBinary(ClientContext ctx, string fileUrlPath)
{
ctx.RequestTimeout = Int32.MaxValue;
var spFile = ctx.Web.GetFileByServerRelativeUrl(fileUrlPath);
var spFileContent = spFile.OpenBinaryStream();
ctx.Load(spFile);
ctx.ExecuteQuery();
MemoryStream stream = new MemoryStream();
if (spFileContent != null && spFileContent.Value != null)
{
spFileContent.Value.CopyTo(stream);
}
return Convert.ToBase64String(stream.ToArray());
}