我正在尝试从文档库中文件夹内的子文件夹下载 txt 文件。
我正在使用 camlQuery 来实现这一点。不幸的是,我没有得到 txt 文件的内容。它有 0 个字节。
public void SaveFolderFiles(string fileName, string libraryName, ClientOM.ClientContext clientContext)
{
ClientOM.List sharedDocumentsList = clientContext.Web.Lists.GetByTitle(libraryName);
ClientOM.CamlQuery camlQuery = new ClientOM.CamlQuery();
camlQuery.FolderServerRelativeUrl = "/Site/Folder/Folder2010/";
camlQuery.ViewXml =
@"<View>
<Query>
<Where>
<Eq>
<FieldRef Name='FileLeafRef'/>
<Value Type='Text'>" + fileName + @"</Value>
</Eq>
</Where>
<RowLimit>1</RowLimit>
</Query>
</View>";
ClientOM.ListItemCollection listItems = sharedDocumentsList.GetItems(camlQuery);
clientContext.Load(sharedDocumentsList);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
if (listItems.Count == 1)
{
ClientOM.ListItem item = listItems[0];
Console.WriteLine("FileLeafRef: {0}", item["FileLeafRef"]);
Console.WriteLine("FileDirRef: {0}", item["FileDirRef"]);
Console.WriteLine("FileRef: {0}", item["FileRef"]);
Console.WriteLine("File Type: {0}", item["File_x0020_Type"]);
ClientOM.FileInformation fileInformation = ClientOM.File.OpenBinaryDirect(clientContext, (string)item["FileRef"]);
using (MemoryStream memoryStream = new MemoryStream())
{
fileInformation.Stream.CopyTo(memoryStream);
using (FileStream fileStream = File.Create(@"D:\" + item["FileLeafRef"].ToString()))
{
memoryStream.CopyTo(fileStream);
}
memoryStream.Flush();
}
}
else
{
Console.WriteLine("Document not found.");
}
}
也许有人有想法?
问候