简体   繁体   English

从共享点检索列表项

[英]Retrieve list items from sharepoint

I am trying to retrieve some Items from a sharepoint 2013 online list. 我正在尝试从sharepoint 2013在线列表中检索一些项目。 I know for sure that there are 3 Items in the list. 我知道列表中有3个项目。 Somehow the code does not return any Items. 代码以某种方式不返回任何项目。 Does anybody know why not? 有人知道为什么不吗? In debugging listItems is empty. 在调试中,listItems为空。

User spUser = null;
SharePointContextToken contextToken;
string accessToken;
Uri sharepointUrl;

string contextTokenString = TokenHelper.GetContextTokenFromRequest(Request);

if (contextTokenString != null)
{
    contextToken = TokenHelper.ReadAndValidateContextToken(contextTokenString, Request.Url.Authority);
    sharepointUrl = new Uri(Request.QueryString["SPHostUrl"]);
    accessToken = TokenHelper.GetAccessToken(contextToken, sharepointUrl.Authority).AccessToken;
    var clientContext = TokenHelper.GetClientContextWithAccessToken(sharepointUrl.ToString(), accessToken);
    Web web = clientContext.Web;
    List list = clientContext.Web.Lists.GetByTitle("CustomListFacturen");

    clientContext.Load(list);

    CamlQuery query = new CamlQuery();
    query.ViewXml = "<View><RowLimit>100</RowLimit></View>";

    ListItemCollection listItems = list.GetItems(query);
    clientContext.Load(listItems);
    clientContext.ExecuteQuery();

    if (listItems.Any())
    {
        ViewBag.Message = "Items are found!!!";
    }
}

I didn't try and run your code, but it looks almost exactly like this code, basic CSOM list operations . 我没有尝试运行您的代码,但是它看起来几乎像这段代码一样,即基本的CSOM列表操作

You don't need that first .Load(list) and you could try using the CamlQuery.CreateAllItemsQuery(100) instead of the CAML. 您不需要首先使用.Load(list)并且可以尝试使用CamlQuery.CreateAllItemsQuery(100)而不是CAML。

您的应用没有足够的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM