I have an AppModel app (Provider hosted, on-premise) and I am trying to add a SharePoint list to deploy with it.
However, the list just seems to be silently ignored - when I deploy and run the app in visual studio, and query the lists with the following C# code, my "FavoriteFoods" list is missing (but other lists are displayed)
Uri hostWeb = new Uri(_httpContext.Request.QueryString["SPHostUrl"]);
using (var clientContext = TokenHelper.GetS2SClientContextWithWindowsIdentity(hostWeb, _httpContext.Request.LogonUserIdentity))
{
var web = clientContext.Web;
clientContext.Load(web, w => w.Lists);
clientContext.ExecuteQuery();
return web.Lists.ToList().Select(x => x.Title).ToList();
}
Edits
- oddly enough, I am able to add the list programmatically, e.g. with
clientContext.Web.Lists.Add(new ListCreationInformation() { Title = "Blah" });
. - The deployment location for the
Elements.xml
files is specified as{SharePointRoot}\Template\Features\{FeatureName}\FavoriteFoodsInstance\
{SharePointRoot}\Template\Features\{FeatureName}\FavoriteFoods\
How can I get the list to deploy and be accessible within the AppModel project?
Other Information:
My most deeply nested Elements.xml file:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ListInstance Title="FavoriteFoods" OnQuickLaunch="TRUE" TemplateType="10000" Url="Lists/FavoriteFoods" Description="My List Instance"></ListInstance>
</Elements>
The other Elements.xml file:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Do not change the value of the Name attribute below. If it does not match the folder name of the List project item, an error will occur when the project is run. -->
<ListTemplate
Name="FavoriteFoods"
Type="10000"
BaseType="0"
OnQuickLaunch="TRUE"
SecurityBits="11"
Sequence="410"
DisplayName="FavoriteFoods"
Description="My List Definition"
Image="/_layouts/15/images/itgen.png"/>
The AppManifest.xml permissions requests:
<AppPermissionRequests>
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="FullControl" />
</AppPermissionRequests>
clientContext.Web.Lists.Add(new ListCreationInformation() { Title = "Blah" });
, which does show up.