检索共享点列表 C# [英] Retrieving Sharepoint List C#
本文介绍了检索共享点列表 C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试检索 SharePoint 列表及其中的所有项目,但我似乎无法获取该列表.我可以正常连接到站点,但是当我尝试检索列表时,出现CollectionNotInitialized"错误.我以管理员身份登录并拥有完全控制权限.谁能帮我解释一下这个问题?这是我的代码
I'm trying to retrieve a SharePoint list and all the items within it, however I CANNOT seem to grab the list. I can connect to the site fine, but when I try to retrieve the list, I get a "CollectionNotInitialized" error. I'm logged in as admin and have full control permissions. Can anyone help explain this issue to me? Here is my code
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#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文