我使用SharePoint CSOM创建了一个函数,使用下面的代码提取文档集合(列表(中的所有文件,但获取3671个文件的列表需要5分钟以上。
有可能加快速度吗?如果有,如何?我见过其他人使用CAML查询从文件夹中提取文件,尽管我不能100%确定如何实现
static SharePointOnlineCredentials SPCreds = new SharePointOnlineCredentials("*********", new System.Net.NetworkCredential("", "*******").SecurePassword);
static string sharepointURL = "https://********";
static string ListName = "Documents";
static string docuemntsStartWith = "Shared Documents";
static List<string> files = new List<string>();
static void Main(string[] args)
{
using (ClientContext clientContext = new ClientContext(sharepointURL))
{
clientContext.Credentials = SPCreds;
List list = clientContext.Web.Lists.GetByTitle(ListName);
clientContext.Load(list);
getFilesInFolder(clientContext, list.RootFolder);
}
Console.WriteLine("Extracted all " + files.Count + " files");
Console.Read();
foreach(string f in files)
{
Console.WriteLine(f);
}
Console.WriteLine("DONE");
Console.Read();
}
public static void getFilesInFolder(ClientContext cc, SP.Folder SPFolder)
{
cc.Load(SPFolder);
cc.Load(SPFolder.Folders);
cc.Load(SPFolder.Files);
cc.ExecuteQuery();
FolderCollection fcol = SPFolder.Folders;
FileCollection filecol = SPFolder.Files;
foreach (SP.File SPF in filecol)
{
files.Add(SPF.ServerRelativeUrl);
}
foreach (SP.Folder SPF in fcol)
{
getFilesInFolder(cc, SPF);
}
}
试试下面的代码,它使用CAML查询:
using System;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;
namespace Microsoft.SDK.SharePointServices.Samples
{
class RetrieveListItems
{
static void Main()
{
string siteUrl = "http://gauti.sharepoint.com/sites/SP";
ClientContext clientContext = new ClientContext(siteUrl);
SP.List oList = clientContext.Web.Lists.GetByTitle("NewBook");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View><Query><Where><Geq><FieldRef Name='ID'/>" +
"<Value Type='Number'>19</Value></Geq></Where></Query><RowLimit>100</RowLimit></View>";
ListItemCollection collListItem = oList.GetItems(camlQuery);
clientContext.Load(collListItem);
clientContext.ExecuteQuery();
foreach (ListItem oListItem in collListItem)
{
Console.WriteLine("ID: {0} nTitle: {1} nBody: {2}", oListItem.Id, oListItem["Title"], oListItem["Body"]);
}
}
}
}