Sharepoint 2010 client object model with camlQuery - file download but no content / 0 byte

半城伤御伤魂 提交于 2019-12-01 06:47:24
Jignesh Rajput

Try this:

using FileInformation and get the MemoryStream

string fileurl = (string)liitem["FileRef"];
FileInformation ffl = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, fileurl);
byte[] bytesarr = ReadFully(ffl.Stream);
MemoryStream mnm = new MemoryStream(bytesarr);

ReadFully function which converts Stream to Bytes array

 public byte[] ReadFully(Stream input)
    {
        byte[] buffer = new byte[16 * 1024];
        using (MemoryStream ms = new MemoryStream())
        {
            int read;
            while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
            {
                ms.Write(buffer, 0, read);
            }
            return ms.ToArray();
        }
    }
Amit Dubey

Export straight to output file ... I think this is the easiest and simplest way of doing it.

FileInformation fInfo = File.OpenBinaryDirect(currentSiteContext, ServerRelativeURL);
System.IO.FileStream outPutFile = System.IO.File.OpenWrite(string.Concat(OutputPath, "\\", DocumentName));
fInfo.Stream.CopyTo(outPutFile);
fInfo.Stream.Close();
outPutFile.Close();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!