我正在尝试检索 SharePoint 列表及其中的所有项目,但我似乎无法获取该列表。我可以正常连接到该网站,但是当我尝试检索列表时,出现“CollectionNotInitialized”错误。我以管理员身份登录并拥有完全控制权限。谁能帮我解释一下这个问题吗?这是我的代码
static void Main(string[] args)
{
try
{
string userName = "//my user name";
string password = "//my password";
SecureString ssPwd = new SecureString();
foreach(char c in password.ToCharArray())
{
ssPwd.AppendChar(c);
}
CamlQuery query = CamlQuery.CreateAllItemsQuery();
ClientContext context = new ClientContext("https://my fake site.com");
SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(userName, ssPwd);
context.Credentials = credentials;
Web web = context.Web;
context.Load(web.Lists);
Microsoft.SharePoint.Client.List list = context.Web.Lists.GetByTitle("Accounts");
context.Load(list);
context.ExecuteQuery();
}
catch
{
// Console.WriteLine();
最佳答案
您可以尝试以下代码:
var lists = web.Lists;
context.Load(lists, all => all
.Where(l => l.RootFolder.Name == "Accounts")
.Include(l => l.Id));
context.ExecuteQuery();
list = lists.Single();
关于c# - 检索 Sharepoint 列表 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42115675/