Add a webpart to page using Onet/Feature

Hi,

Custom home page is quite common requirement for any development project. This post helps you if you need to add out of box web part to page. This post contains good details how to deploy custom page.

The AllUsersWebPart tag allow us to insert a custom/Out of box web part and It also contains few attributes which are used to place web part. Two important attributes are WebPartOrder and WebPartZone attributes. The content of the tag is the dwp (or webpart) of any web part. The tag cloud dwp code example is given below:
<AllUsersWebPart WebPartZoneID="Right" WebPartOrder="3">           <![CDATA[<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">                       <Title>Tag Cloud</Title>                       <Description>Displays the most popular subjects being tagged inside your organization.</Description>                       <FrameType>TitleBarOnly</FrameType>                       <ChromeType>None</ChromeType>                       <AllowRemove>true</AllowRemove>                       <AllowMinimize>true</AllowMinimize>                       <Assembly>Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>                      <TypeName>Microsoft.SharePoint.Portal.WebControls.TagCloudWebPart</TypeName>                     </WebPart>         ]]>         </AllUsersWebPart> 

For .webpart, following
<AllUsersWebPart WebPartZoneID="MiddleLeftZone" WebPartOrder="1">     <![CDATA[                                                     <webParts>         <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">           <metaData>             <type name="MyClass, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f3b9d1137704f880" />             <importErrorMessage>No se puede importar este elemento Web.</importErrorMessage>           </metaData>           <data>             <properties>               <property name="AllowClose" type="bool">False</property>               <property name="AllowMinimize" type="bool">False</property>               <property name="AllowConnect" type="bool">True</property>               <property name="ChromeType" type="chrometype">None</property>               <property name="Hidden" type="bool">False</property>               <property name="AllowEdit" type="bool">False</property>               <property name="AllowZoneChange" type="bool">False</property>               <property name="MissingAssembly" type="string">No se puede importar este elemento Web.</property>               <property name="ChromeState" type="chromestate">Normal</property>             </properties>           </data>         </webPart>       </webParts>     ]]>   </AllUsersWebPart> 

AllUserWebPart tag can be used in onet.xml under "File" tag. If we are adding the custom page using the feature then also the same way we can define this tag value to the File tag.

Thanks for your time :)...

Comments

Popular posts from this blog

Hide Ribbon on SharePoint 2013 using CSS

Get Comment Count in SharePoint

Configure external site as content sources in sharepoint search