Reputation: 2523
I have a provider hosted app. and I'm trying to get to the listitems in a list that is on my host-web.
I can get a list of all the lists I have. But when I try to get to the listitems, it's always empty.
var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);
using (var clientContext = spContext.CreateUserClientContextForSPHost())
{
clientContext.Load(clientContext.Web, web => web.Title);
clientContext.ExecuteQuery();
ListCollection lists = clientContext.Web.Lists;
List list = lists.GetByTitle("TestList");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View><RowLimit>100</RowLimit></View>";
Microsoft.SharePoint.Client.ListItemCollection items = list.GetItems(camlQuery);
clientContext.Load<ListCollection>(lists);
clientContext.Load<List>(list);
clientContext.Load<Microsoft.SharePoint.Client.ListItemCollection>(items);
clientContext.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.ListItem item in items)
{
Response.Write("<br />" + item.FieldValues["Title"]);
}
}
In the AppManifest.xml i added a 'full control' permission for list
Upvotes: 1
Views: 3491
Reputation: 1
Your code is perfectly fine ....
Just you have to make change in "AppManifest.xml" file permission give site collection as full control as you are using host web .
Upvotes: 0
Reputation: 26
In the AppManifest.xml add a READ permission for list and Web
Upvotes: 1
Reputation: 2523
Apparently I did everything correct. When installing I still had to say which lists it had full control on.
Upvotes: 0