Saturday, 2 March 2013

SharePoint 2013: Provision AppPart/ClientWebPart through Elements.xml

In my last post, we saw how we can add an app part to page by directly adding the app part code in our .aspx pages. Here is a link to my last post for those interested:

Now lets take a look at how we can provision the app part declaratively through Elements.xml file. First, you will have to make sure that the App is installed on the site on which you are trying to deploy the app part. Otherwise your app part will not be provisioned correctly.

Here is the code to put in your Elements.xml file:

Keep in mind the following few properties:

ProductId: Its the ProductId of your App. A unique identifier which differentiates your app. Please see my last post on how you can get the ProductId of your App.

FeatureId: The same as ProductId. On first glance, it looks like it should be the GUID of the feature present in your app. But thats not the case as far as I know.

ProductWebId: A new Random GUID

WebPartName: The file name of the WebPart found in your Client WebPart XML file. See previous post for  more details.

Custom Properties: You can even provision custom properties and set their default values from here. In the example, I have the myEnumProp as a custom property in my App Part. Here is a link on how to add custom web part properties to your app part:


Anonymous said...

Hi and many thanks for this - just what I needed. However, there is an error in that feature id and product id must not be the same - the last character in the guid is one different (see your own code).

Have found that if you make them identical, then web part fails on the page as someone else I believe noted on your other post.

Answer as you suggested is to try checking in Designer first and you will see it too has the slightly differing Guids. Amend the Guids in the CAML and it works.

Anyway - your post was an enormous help - thanks!

Satya Agarwal Blog said...


I have tried this approach but getting App is not installed on this site. i want to know how to deploy the App in all the sites in a site collection. I have tried it from APP catalog and that App is available in site contents but its not adding on site default page and showing error message. so i need to go and add that app to my newly created site by trusting this App and then it start working. is there any way so i can add my app in all sites so it will display after provisioning the site.

Bhoopathy E said...

Good Post! But I am facing the below issue

The MyFavApp ClientWebPart feature d21cfbef-1576-4db2-bb10-1d9ae83e558a is not installed or is not Active. Correlation ID: adfe0e9d-302e-2000-0d17-77f1f7acfff8.

Can you help me to solve this issue