Provisioning CEWP on Share Point Pages


Project Structure:-

1. Add Default Data to Content Editor Web Part

Create any Pages in Solution and Add necessary tag:-


<asp:Content ContentPlaceHolderId="PlaceHolderPageTitle" runat="server">
<SharePoint:ListItemProperty Property="BaseName" maxlength="40" runat="server" />
</asp:Content>
<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
<meta name="GENERATOR" content="Microsoft SharePoint" />
<meta name="ProgId" content="SharePoint.WebPartPage.Document" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="CollaborationServer" content="SharePoint Team Web Site" />

</asp:Content>

<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">

<WebPartPages:WebPartZone runat="server" title="loc:TitleBar" id="TitleBar" AllowLayoutChange="false" AllowPersonalization="false" Style="display:none;" >

 </WebPartPages:WebPartZone>

</asp:Content>


Add XML tag in Element File with C-Data tag

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="TestModule" Url="SitePages">

    <File Path="TestModule\asas.aspx" Url="TestModule/asas.aspx" Type="GhostableInLibrary"  >
      <Property Name="Title" Value="CEWP- Provisioning"/>

      <AllUsersWebPart WebPartZoneID="TopZone" WebPartOrder="0">

        <![CDATA[<WebPart xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/WebPart/v2">
                  <Title>Content Editor</Title>
                      <FrameType>Default</FrameType>
                      <Description>Allows authors to enter rich text content.</Description>
                      <IsIncluded>true</IsIncluded>
                      <ZoneID>TopZone</ZoneID>
                      <PartOrder>0</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/15/images/mscontl.gif</PartImageLarge>
                      <IsIncludedFilter />
                      <Assembly>Microsoft.SharePoint, Version=15.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"><![CDATA[ ​This is my test Content editor webpart ]]]]><![CDATA[></Content>
                      <PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
                      </WebPart>]]>


      </AllUsersWebPart>
      
    </File>
  </Module>
</Elements>


2. Add HTML File link to Content Editor Web Part


Use above code as is and replace the Content Link tag with below mention setting.

Note:- here i am using HTML file reference from style library. 

 <ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor">~SiteCollection/Style%20Library/HTMLFiles/abc.html</ContentLink>



No comments:

Post a Comment