0

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>
4
  • What type of app is it? It needs to be a SharePoint Hosted app to contain lists and other SharePoint artifacts Commented May 24, 2013 at 16:03
  • Thanks for the comment. It is a provider hosted, on-premise app. But I'm not convinced that it has to be a SharePoint hosted app - since I can add the lists to the SharePoint project of the solution. Do you have an msdn or some such reference that documents a SharePoint hosted only restriction?
    – Nathan
    Commented May 24, 2013 at 17:21
  • msdn.microsoft.com/en-us/library/fp179887.aspx here are details about all hosting alternatives. I also se you are missing the permisson for managing lists in your AppManifest aswell. Commented May 24, 2013 at 17:31
  • @RobertLindgren Interesting, I see that the page only mentions sharepoint artifacts in the "Share Point" hosted section, but (as far as I can see) doesn't explicitly say they are unavailable in the other hosting options. Oddly enough, whether or not I add the permissions for managing lists in the AppManifest, as you suggested, my list added to the SharePoint project still doesn't show up, but in either case I am able to programmatically add a list, e.g. clientContext.Web.Lists.Add(new ListCreationInformation() { Title = "Blah" });, which does show up.
    – Nathan
    Commented May 24, 2013 at 18:08

2 Answers 2

1

Any list you deploy as part of you App will be added to the AppWeb (yes such a web is created when you add SharePoint items to your App, even though the App is Provider hosted) not to the HostWeb

3
  • Hi, that sounds like a reasonable explanation as to why. Do you know how to access that resource in the AppWeb using the .NET CSOM?
    – Nathan
    Commented May 24, 2013 at 20:37
  • Have you tried to replace SPHostUrl in your code with SPAppWebUrl? Commented May 24, 2013 at 20:42
  • Replacing the SPHostUrl with SPAppWebUrl did the trick. So it looks like I have two choices for where to interact with SharePoint lists. Thanks!
    – Nathan
    Commented May 30, 2013 at 16:51
0

You'll find details on how to create a cloud-hosted app (provider-hosted or autohosted) that includes a custom SharePoint list and content type there :

http://msdn.microsoft.com/en-us/library/fp179936.aspx

It is using two apps with cross-domains javascript or OAuth & REST OData webservices to communicate between them. As you'll see, it is using the SPAppWebUrl instead of SPHostUrl because the lists are in the App Web created for the app.

This is thus possible but sometimes it is easier to create your list programmatically if it doesn't exists, thus allowing you to have the list in the main sharepoint site instead of in an app web.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.