1

I have the following code, which successfully gets the list, but the spListItems variable never seems to never yield any results, even though the spList reports having listitems.

Any Ideas???

        var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
        ListItemCollection spListItems = null;
        List spList = null;

        using (var clientContext = spContext.CreateUserClientContextForSPHost())
        {
            if (clientContext != null)
            {
                CamlQuery caml = new CamlQuery();

                // initilize our collections and vars
                spList = clientContext.Web.Lists.GetByTitle("EclipseAppPages");
                clientContext.Load<List>(spList);
                clientContext.ExecuteQuery();

                // do it again 
                spListItems = spList.GetItems(caml);
                clientContext.Load<ListItemCollection>(spListItems);
                clientContext.ExecuteQuery();

                // loop items and populate model
                foreach (ListItem l in spListItems)
                {
                    model.Add(l);
                }
            }
        }

Edit 18-09: A little bit more info into this, this code is hosted inside a 'autohosted' mvc app for sharepoint. I am accessing the HostWeb from my AppWeb, my first conclusion would be permissions, however the fact that im getting the list back, and interestingly when i debug the variable the spListItems has an item count of > 0 but for some reason the context ISNT lazy loading the values.

4

2 回答 2

0

原来是应用程序权限,我找到了解决方案,试图找到查询字符串过滤器问题的解决方案。

如果您遇到同样的问题,请进入您的 AppParts AppManifest.xml 并添加以下节点:

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

或者,您可以通过 Visual Studio 向导执行此操作,双击您的 AppManifest 文件,转到权限选项卡,范围为“Web”,权限为“选择相关权限”。

有关应用程序权限的更多信息,请访问http://msdn.microsoft.com/en-us/library/fp179892(office.15).aspx

于 2013-09-23T10:55:32.350 回答
-1

查询结果为空的原因是 CamlQuery 对象没有 ViewXml 或 Query 属性值。阅读以下有关如何查询 SharePoint 列表的文章。http://msdn.microsoft.com/en-us/library/ff798388.aspx

此外,出于性能考虑,使用 RowLimit 和 ViewFields 属性来限制结果。

或者,如果您对此感到满意,也可以使用 Linq to SharePoint。

于 2013-09-18T16:44:34.487 回答