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

后端 未结 2 775
抹茶落季
抹茶落季 2021-01-13 18:13

I\'m trying to download a txt file from a subfolder within a folder in a document library.

I\'m using camlQuery to achieve this. Unfortunately, i get no content of t

相关标签:
2条回答
  • 2021-01-13 18:23

    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();
            }
        }
    
    0 讨论(0)
  • 2021-01-13 18:29

    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();
    
    0 讨论(0)
提交回复
热议问题