Help appreciated in resolving this issue, below source throws System.OutOfMemory exception 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());
}
Thanks
解决方案Check if this works:
return Convert.ToBase64String( stream.GetBuffer(), stream.Length);
How large is the file?