In this article, you will learn how to add web part to a page programmatically.
The web parts can be appended to a page using the webpart xml content. Each and every webpart present on SharePoint is represented by xml content. This can be witnessed by exporting the webpart from any page. In this article, you will learn how to add the webpart using CSOM approach.
The following denotes a content editor webpart xml content.
XML:
XML:
- "<?xml version="1.0" encoding="utf-8"?>
- <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>MyInfo</Title>
- <FrameType>None</FrameType>
- <Description>Allows authors to enter rich text content.</Description>
- <IsIncluded>true</IsIncluded>
- <ZoneID>BottomZone</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">/Style Library/Txt/MyInfo.txt</ContentLink>
- <Content xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
- <PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
- </WebPart>

Murali KrisPosted Dec 15, 2017, 1:10 AM
Hi thanks for you article. but also i want to know how to set zoneid to wiki page, i can place webpart on wiki page but it is placing bottom of the page, here we want to place top of the page. please help me here, i have tried changing with zoneid and exported DWP file from webpart. no luck it is adding only bottom of the page. Thanks in Advance.