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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> | |
<Module Name="HomePages" Url="Pages"> | |
<File Path="HomePages\Home.aspx" Url="Home.aspx" Type="GhostableInLibrary"> | |
<AllUsersWebPart WebPartZoneID="Left" WebPartOrder="1"> | |
<![CDATA[ | |
<webParts> | |
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3"> | |
<metaData> | |
<type name="Microsoft.SharePoint.WebPartPages.ClientWebPart, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /> | |
<importErrorMessage>Cannot import this Web Part.</importErrorMessage> | |
</metaData> | |
<data> | |
<properties> | |
<property name="TitleIconImageUrl" type="string" /> | |
<property name="HelpMode" type="helpmode">Navigate</property> | |
<property name="Direction" type="direction">NotSet</property> | |
<property name="ExportMode" type="exportmode">All</property> | |
<property name="HelpUrl" type="string" /> | |
<property name="Hidden" type="bool">False</property> | |
<property name="Description" type="string">Description of My App Part</property> | |
<property name="FeatureId" type="System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">9bed54d4-8a85-422f-9318-1000e4d475ee</property> | |
<property name="CatalogIconImageUrl" type="string" /> | |
<property name="Title" type="string">Web Part Title</property> | |
<property name="AllowHide" type="bool">True</property> | |
<property name="ProductWebId" type="System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">a83c188b-c3af-4b37-85fa-e160f27b4e4d</property> | |
<property name="AllowZoneChange" type="bool">True</property> | |
<property name="ChromeType" type="chrometype">Default</property> | |
<property name="AllowConnect" type="bool">True</property> | |
<property name="Width" type="unit" /> | |
<property name="Height" type="unit" /> | |
<property name="WebPartName" type="string">MyWebPart</property> | |
<property name="TitleUrl" type="string" /> | |
<property name="AllowEdit" type="bool">True</property> | |
<property name="AllowMinimize" type="bool">True</property> | |
<property name="ProductId" type="System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">9bed54d4-8a85-422f-9318-1000e4d475ed</property> | |
<property name="AllowClose" type="bool">True</property> | |
<property name="ChromeState" type="chromestate">Normal</property> | |
<property name="myEnumProp" type="string">EnumValue1</property> | |
</properties> | |
</data> | |
</webPart> | |
</webParts> | |
]]> | |
</AllUsersWebPart> | |
</File> | |
</Module> | |
</Elements> |
Keep in mind the following few properties:
3 comments:
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!
Hi,
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.
Thanks
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
Post a Comment