Tuesday, April 24, 2012

Content Editor web part in onet.xml

When tried to add a content editor web part to site definition. It works with me for simple content but when try to add tagged content like HTML it failed. After some Investigation I found solution by putting content into value tag <Value> instead of putting it direct into content property like this example:



<AllUsersWebPart WebPartZoneID="SurveyBtn" WebPartOrder="5">
        <![CDATA[
        <WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2">
            <Title>Content Editor</Title>
            <FrameType>None</FrameType>
            <Description>Use for formatted text, tables, and images.</Description>
            <IsIncluded>true</IsIncluded>
            <ZoneID>WebPartZoneMiddleR</ZoneID>
            <PartOrder>5</PartOrder>
            <FrameState>Normal</FrameState>
            <Height />
            <Width />
            <AllowRemove>true</AllowRemove>
            <AllowZoneChange>true</AllowZoneChange>
            <AllowMinimize>true</AllowMinimize>
            <AllowConnect>true</AllowConnect>
            <AllowEdit>true</AllowEdit>
            <AllowHide>true</AllowHide>
            <IsVisible>true</IsVisible>
            <DetailLink />
            <HelpLink />
            <HelpMode>Modeless</HelpMode>
            <Dir>Default</Dir>
            <PartImageSmall />
            <MissingAssembly>Cannot import this Web Part.</MissingAssembly>
            <PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge>
            <IsIncludedFilter />
            <Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
            <TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>
            <ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
            <Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">
              <Value>
               &lt;div class=&quot;SurveyLocation&quot;&gt;&lt;a href=&quot;../Surveys&quot;&gt;&lt;img src=&quot;/_LAYOUTS/PMO.Departments/images/icn_survey.jpg&quot; alt=&quot;&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
              </Value>
            </Content>
            <PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
          </WebPart>
]]>
      </AllUsersWebPart>

No comments: