4

I have requirement to add Client Web Part to .aspx page programmatically in SharePoint provider hosted app, I have tried this link, but this is for SharePoint hosted app, below code is not working for provider hosted app page because of restriction of server side tags,

 <asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
 </asp:Content>
 <asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" runat="server">
 <WebPartPages:WebPartZone runat="server" AllowPersonalization="true" ID="WebPartZone2" FrameType="TitleBarOnly" Title="Bottom" Orientation="Vertical">
    <ZoneTemplate>
        <WebPartPages:ClientWebPart runat="server"
             FeatureId="17297f8b-5333-46d8-8af6-78e282ea4f22"
             ProductWebId="57278E26-4B76-4AC8-8EFE-C52FB279635E"
             WebPartName="MyWebPart"
             Title="My WebPart Title"
             Description="WebPart Description"
             WebPart="true">
            <Properties>
                <WebPartPages:ClientWebPartProperty Name="myIntProp" Value="7"></WebPartPages:ClientWebPartProperty>
                <WebPartPages:ClientWebPartProperty Name="myEnumProp" Value="EnumValue1"></WebPartPages:ClientWebPartProperty>
            </Properties>
        </WebPartPages:ClientWebPart>
    </ZoneTemplate>
</WebPartPages:WebPartZone>
</asp:Content>

Is there any alternative way to achieve the same?

  • What is wrong with this approach? Another way is to use CSOM to add the web part, it is quite easy – eirikb Mar 28 '14 at 8:28
2

I followed this blogpost: http://www.vrdmn.com/2013/03/sharepoint-2013-declaratively-add-app.html

The only modification I did was that I had to find the FeatureId by powershell:

Get-SPFeature -web <url to your site> | select DisplayName, Id

One of the features has a DisplayName and ID that is a guid almost identical to the ProductId. In my case, only the last character differed. This features guid is the id for the FeatureId property.

It is pretty strange that it seems impossible to find the FeatureId without first installing the app and then check for the id through powershell, but I haven't found any other way yet.

  • That PowerShell will not work in SharePoint Online. – wjervis Aug 15 '14 at 11:36
0

Add client app part to sharepoint site page. open site page in sharepoint designer. It will show you feature id ,product id and all other details.

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.