I am trying to add new web part to the SharePoint page using Managed Client Object Model that will display a list. I can't seem to be able to figure out the code of the web part's XML that is responsible for list infromation.
Here is what I have created so far:
File page;
LimitedWebPartManager webPartManager;
WebPartDefinition wpd;
page = clientContext.Web.GetFileByServerRelativeUrl("/SitePages/Home.aspx");
page.CheckOut();
webPartManager = page.GetLimitedWebPartManager(PersonalizationScope.Shared);
wpd = webPartManager.ImportWebPart(webPartXml); // This XML string is what I need to figure out!
webPartManager.AddWebPart(wpd.WebPart, zone, order);
page.CheckIn(string.Empty, CheckinType.MajorCheckIn);
For example, here is the XML string that successfully creates a Content Editor Web Part:
<?xml version="1.0" encoding="utf-8"?>
<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>My web part added through Client Object Model</Title>
<FrameType>Default</FrameType>
<Description>It displays the custom content quite well!</Description>
<IsIncluded>true</IsIncluded>
<ZoneID>Left</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/images/mscontl.gif</PartImageLarge>
<IsIncludedFilter />
<Assembly>Microsoft.SharePoint, Version=13.0.0.0, Culture=neutral, PublicKeyToken=94de0004b6e3fcc5</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 text!
<DIV> </DIV>
<DIV>Blah blah blah</DIV>
<DIV> </DIV>
<DIV>And another blah</DIV>]]>
</Content>
<PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" />
</WebPart>
I need one similar to it which would create a List Web Part. The code after the <Assembly>
tag should be adjusted for SharePoint List Web Parts. Does anyone know what the XML should look like? Thanks!