Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用CSOM在提供商托管的SharePoint应用程序中获取列表项_Sharepoint_Office365_Csom_Sharepoint Online - Fatal编程技术网

使用CSOM在提供商托管的SharePoint应用程序中获取列表项

使用CSOM在提供商托管的SharePoint应用程序中获取列表项,sharepoint,office365,csom,sharepoint-online,Sharepoint,Office365,Csom,Sharepoint Online,我有一些简单的代码,使用CSOM读取SharePoint Online中托管的SharePoint列表中的项目 List list = ClientContext.Web.Lists.GetById(id); ClientContext.Load(list, a => a.ItemCount, a => a.Title); ListItemCollection items = lis

我有一些简单的代码,使用CSOM读取SharePoint Online中托管的SharePoint列表中的项目

        List list = ClientContext.Web.Lists.GetById(id);

        ClientContext.Load(list,
            a => a.ItemCount,
            a => a.Title);


        ListItemCollection items = list.GetItems( CamlQuery.CreateAllItemsQuery());

        ClientContext.Load(items);
        ClientContext.ExecuteQuery();

        foreach (ListItem li in items)
        {
        .... // Do some Stuff ...
        }
在ExecuteQuery调用结束时,我可以访问列表标题(“MyList”)和记录计数(总共7项),但是ListItemsCollection项的计数始终为零

不会抛出任何错误

我需要做什么才能真正获取列表项?我是否错过了另一个呼叫CSOM,或者他们的呼叫可能是一个权限问题(SharePoint Online不会告诉我是否是这样吗?)


感谢您的帮助

尝试使用“include”在客户端上下文中获取数据

Load(list,a.Include(p=>p.ItemCount,p=>p.Title); 然后检查项目计数和标题是否存在

请让我们知道此列表是否在应用程序中。
如果它位于主机web上,则必须在appmanifest.xml->permission选项卡下提供读取权限

我在使用Sharepoint 2013内部部署和STS作为信任代理时遇到同样的问题

相同的行为,没有错误,并且我使用CamlQuery.CreateAllItemsQuery()获得“全选”CamlQuery时,得到的项目/文档为零

我通过页面创建了一个新的应用程序主体,解决了这个问题:

/layouts/15/appregnew.aspx
 /layouts/15/appinv.aspx 
然后使用页面分配足够的权限:

/layouts/15/appregnew.aspx
 /layouts/15/appinv.aspx 
到包含列表的HostWeb(而不是AppWeb)。在我的情况下:

<AppPermissionRequests AllowAppOnlyPolicy="true">
    <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="Manage"/>
  </AppPermissionRequests>


仍然存在一个bug(Sharepoint bug),因为在本例中,它不会抛出“拒绝访问”错误

是。项目计数和标题始终存在…这不是问题。问题是我无法获取列表项目。上述代码仅针对应用程序下的列表或库运行,而不是在主机web上。对于主机web,您必须提供权限。请让我们知道此列表是否与应用程序内的列表一起运行。如果它在t上主机web然后您必须在appmanifest.xml->permission选项卡下提供读取权限该列表位于主机web上。如果我向清单添加权限,允许最终用户选择提供商托管的应用程序可以读取的列表,那么提供商托管的应用程序如何知道它有权访问的列表?最好是在您授予perm时ission以read的形式访问web级别,然后用户可以从列表中检索数据。此外,您必须在代码中指定要引用的列表或迭代web.lists。