gpt4 book ai didi

c# - 获取具有文件夹 ID 的子文件 - 客户端对象模型

转载 作者:行者123 更新时间:2023-11-30 22:07:55 25 4
gpt4 key购买 nike

我想获取一些文件夹 - 子文件。我在列表中有所有文件夹 SharePoint ID。我的代码可以工作,但性能很差,因为有很多 context.ExecuteQuery;

我想用 Caml 查询实现它。

using (var context = new ClientContext("http://xxx/haberlesme/"))
{
var web = context.Web;
var list = context.Web.Lists.GetById(new Guid(target));

int[] siraliIdArray;
//siraliIdArray = loadSharePointIDList(); think like this

for (var j = 0; j < siraliIdArray.Count; j++)
{
var folderName = listItemCollection[j]["Title"].ToString();//Folder Name
var currentFolder = web.GetFolderByServerRelativeUrl("/haberlesme/Notice/" + folderName);
var currentFiles = currentFolder.Files;

context.Load(currentFiles);

//I don't want to execute for n folder n times. I want to execute n folder 1 time.
context.ExecuteQuery();

var ek = new LDTOTebligEk();

//I don't want to add one - one
foreach (var file1 in currentFiles)
{
ek.DokumanPath = urlPrefix + folderName + "/" + file1.Name;
ek.DokumanAd = file1.Name;

ekler.Add(ek);

}
}
}

例如,我有 100 个文件夹,但我想在一次执行

中获取 10 个文件夹子文件夹

最佳答案

由于 CSOM API 支持 Request Batching :

The CSOM programming model is built around request batching. When you work with the CSOM, you can perform a series of data operations on the ClientContext object. These operations are submitted to the server in a single request when you call the ClientContext.BeginExecuteQuery method.

您可以重构您的代码,如下所示:

var folders = new Dictionary<string,Microsoft.SharePoint.Client.Folder>();
var folderNames = new[] {"Orders","Requests"};
foreach (var folderName in folderNames)
{
var folderKey = string.Format("/Shared Documents/{0}", folderName);
folders[folderKey] = context.Web.GetFolderByServerRelativeUrl(folderKey);
context.Load(folders[folderKey],f => f.Files);
}
context.ExecuteQuery(); //execute request only once




//print all files
var allFiles = folders.SelectMany(folder => folder.Value.Files);
foreach (var file in allFiles)
{
Console.WriteLine(file.Name);
}

关于c# - 获取具有文件夹 ID 的子文件 - 客户端对象模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22629710/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com