Provisioning Resources To AppWeb using CAML

Open Visual Studio

Create New Project

Choose a Project Template Name: SharePoint Add-In or Apps for SharePoint

Now Add new Item: Select List -> Give a Name "Categories"

Remove the Description of the List:

In Columns Window Add two new Columns:

Add new List: Products

Now create columns for this List: see below image this will also explain, how to create a LookUp Column:

Now this List is successfully linked to Categories List Title, for showing LookUp values for Category field.

Now add another columns to this List:

 

Now go to the Categories Node and Open Element.xml for the List Definition:

Set Type="10001"

After this Open ListInstance Element.xml file:

And set its TemplateType="10001" , this is very important to match the Instance to Definition.

Now let's Add some data to Categories List:

Add the Data: to Categories List

CategoriesData.xml (1.94 kb)

ProductsData.xml (40.52 kb)

Do this whole steps for Products List

Set Type="10002"

Set TemplateType="10002" 

Add Data Rows to the Products List Instance-> Element.xml file, Find data file on above given link.

After all these changes Come back to your Default.aspx page and add little bit UI for access these Lists:

Run :

Before Run confirm all the resources is available in the Feature or Not:

In this case you see not added, so add all required resources to this web scoped feature.

After adding required resources your Feature will look like below image:

Now Run your App for install to the SharePoint online site: As you Start you see in the output window the app is uploading and start installing process:

Wait until the project is installed successfully. After installation you see the below output screen:

Click on Categories and Products lists and see the List that available in your App:

 

This covers provisioning resources to the AppWeb using CAML, this technique is only used for provisioning the resources to the AppWeb it can't be used to provision the HostWeb, as you find their is only one scope available for that is : Web scope.

If you really want to provision to the HostWeb then you have to write some JavaScript to do this kind of task.

Voila! Enjoy SharePoint App Development.........

 

Add comment