我正在尝试从sharepoint 2013在线列表中检索一些项目。我确信列表中有3个项目。不知何故,代码不会返回任何项目。有谁知道为什么不呢?在调试中,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!!!";
}
}
答案 0 :(得分:1)
我没有尝试运行您的代码,但它看起来几乎与此代码basic CSOM list operations完全相同。
您首先不需要.Load(list)
,您可以尝试使用CamlQuery.CreateAllItemsQuery(100)
代替CAML。
答案 1 :(得分:0)
您的应用没有足够的权限。