0

I am new to SharePoint App Model. I am creating one demo SharePoint hosted App. And I want to create a list and access the data from this list.

Can anyone please help me out with the scenario that whether I should create my list in App web or host web ?

OR How do I decide whether to create my list on host web or App web ?

Thanks in advance.

1

Create list in App web or in host web?

  • List in App web can be created declaratively in designer and if you need another changes you can change the XML itself.
  • List in host web needs to be provisioned by code (C#, JavaScript) in AppInstall event
  • List in App web is not visible to a user in Site contents and lies at different url
  • When the App is deleted, everything in App web is also deleted (all App web can be restored from Recycle bin)
  • You should not change settings of a list in App web because it can be overriden in newer version of App

So it's really up to you where you will host the list.

Here you can find nice and simple example of SharePoint-hosted Add-In with list provisioning inside App web https://msdn.microsoft.com/en-us/library/office/fp142379.aspx

Here is example of creating list with column in a host web.

using (ClientContext cc = new ClientContext(auth.Url))
{
    cc.Credentials = new SharePointOnlineCredentials(auth.UserName, auth.Password);

    ListCreationInformation listInfo = new ListCreationInformation();
    listInfo.Title = "Shared documents";
    listInfo.Url = "SharedDocuments";
    listInfo.TemplateType = 101;

    List newlist = cc.Web.Lists.Add(listInfo);
    cc.ExecuteQuery();

    newlist.Fields.AddFieldAsXml("<Field Name='Column' DisplayName='Column name' Type='Text' />", addToDefaultView: true, options: AddFieldOptions.AddFieldInternalNameHint);
    cc.ExecuteQuery();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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