4

I have to add a few webparts to a default page using the Client side object model. For the most part this goes fine, I can add a XSLT and content query webparts.

However, when i try to add a ListViewWebPart, I get the exceedingly helpful "Unknown Error" I use the following code to add the webpart

        Microsoft.SharePoint.Client.File oFile = context.Web.GetFileByServerRelativeUrl(newWeb.ServerRelativeUrl + "/default.aspx");
        LimitedWebPartManager limitedWebPartManager = oFile.GetLimitedWebPartManager(PersonalizationScope.Shared);

        WebPartDefinition webDef = limitedWebPartManager.ImportWebPart(webPartXmlString));
        limitedWebPartManager.AddWebPart(webDef.WebPart, "Right", 0);
        context.ExecuteQuery();

and the following 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>Agenda</Title>
  <FrameType>Default</FrameType>
  <Description />
  <IsIncluded>true</IsIncluded>
  <ZoneID>Right</ZoneID>
  <PartOrder>1</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>/Lists/Agenda</DetailLink>
  <HelpLink />
  <HelpMode>Modeless</HelpMode>
  <Dir>Default</Dir>
  <PartImageSmall />
  <MissingAssembly>Kan dit webonderdeel niet importeren.</MissingAssembly>
  <PartImageLarge>/_layouts/15/images/itevent.png?rev=32</PartImageLarge>
  <IsIncludedFilter />
  <Assembly>Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
  <TypeName>Microsoft.SharePoint.WebPartPages.ListViewWebPart</TypeName>
  <WebId xmlns="http://schemas.microsoft.com/WebPart/v2/ListView">00000000-0000-0000-0000-000000000000</WebId>
  <ListViewXml xmlns="http://schemas.microsoft.com/WebPart/v2/ListView">&lt;View MobileView="TRUE" Type="CALENDAR" Hidden="TRUE" TabularView="FALSE" Scope="Recursive" RecurrenceRowset="TRUE" DisplayName="" Url="/default.aspx" Level="1" BaseViewID="2" ContentTypeID="0x" MobileUrl="_layouts/15/mobile/viewdaily.aspx" ImageUrl="/_layouts/15/images/events.png?rev=33"&gt;&lt;ViewFields&gt;&lt;FieldRef Name="EventDate" /&gt;&lt;FieldRef Name="EndDate" /&gt;&lt;FieldRef Name="Title" /&gt;&lt;FieldRef Name="fRecurrence" Explicit="TRUE" /&gt;&lt;/ViewFields&gt;&lt;CalendarViewStyles&gt;&amp;lt;CalendarViewStyle  Title='Dag' Type='day' Template='CalendarViewdayChrome' Sequence='1' Default='TRUE' /&amp;gt;&amp;lt;CalendarViewStyle  Title='Week' Type='week' Template='CalendarViewweekChrome' Sequence='2' Default='FALSE' /&amp;gt;&amp;lt;CalendarViewStyle  Title='Maand' Type='month' Template='CalendarViewmonthChrome' Sequence='3' Default='FALSE' /&amp;gt;&lt;/CalendarViewStyles&gt;&lt;Aggregations Value="Off" /&gt;&lt;RowLimit&gt;0&lt;/RowLimit&gt;&lt;Mobile MobileItemLimit="3" /&gt;&lt;Toolbar Type="Standard" /&gt;&lt;ViewHeader /&gt;&lt;ViewBody /&gt;&lt;ViewFooter /&gt;&lt;ViewEmpty /&gt;&lt;ParameterBindings&gt;&lt;ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" /&gt;&lt;ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" /&gt;&lt;/ParameterBindings&gt;&lt;ViewData&gt;&lt;FieldRef Name="Title" Type="CalendarMonthTitle" /&gt;&lt;FieldRef Name="Title" Type="CalendarWeekTitle" /&gt;&lt;FieldRef Name="Location" Type="CalendarWeekLocation" /&gt;&lt;FieldRef Name="Title" Type="CalendarDayTitle" /&gt;&lt;FieldRef Name="Location" Type="CalendarDayLocation" /&gt;&lt;/ViewData&gt;&lt;Query&gt;&lt;Where&gt;&lt;DateRangesOverlap&gt;&lt;FieldRef Name="EventDate" /&gt;&lt;FieldRef Name="EndDate" /&gt;&lt;FieldRef Name="RecurrenceID" /&gt;&lt;Value Type="DateTime"&gt;&lt;Month /&gt;&lt;/Value&gt;&lt;/DateRangesOverlap&gt;&lt;/Where&gt;&lt;/Query&gt;&lt;/View&gt;</ListViewXml>
  <ListName xmlns="http://schemas.microsoft.com/WebPart/v2/ListView">{{GUID}}</ListName>
  <ListId xmlns="http://schemas.microsoft.com/WebPart/v2/ListView">{GUID}</ListId>
  <ViewFlag xmlns="http://schemas.microsoft.com/WebPart/v2/ListView">11022345</ViewFlag>
  <ViewFlags xmlns="http://schemas.microsoft.com/WebPart/v2/ListView">Html Hidden Recursive RecurrenceRowset Calendar FilesOnly Mobile</ViewFlags>
  <ViewContentTypeId xmlns="http://schemas.microsoft.com/WebPart/v2/ListView">0x</ViewContentTypeId>
</WebPart>

The XML is generated by exporting a sharepoint list webpart, and i can import it through the Gui just fine. (Naturally the {GUID} is replaced with the actual List Id)

Does anyone have any idea what could cause the Unknown error, or at least how i could debug this?

1
3

Simplify your XML schema. You probably have some unsupported properties defined.

This XML schema worked with me while I was adding listviewwebparts to a page in CSOM

<?xml version="1.0" encoding="utf-8" ?>
<webParts>
  <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
    <metaData>
      <type name="Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
      <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
    </metaData>
    <data>
      <properties>
        <property name="ListUrl" type="string">Documents</property>
        <property name="MissingAssembly" type="string">Cannot import this Web Part.</property>
      </properties>
    </data>
  </webPart>
</webParts>
2
  • ^^ this is great. I had a custom list so had to use ListUrl "Lists/MyList" Jun 2 '16 at 13:36
  • I was getting an error in my On Premises 2013 environment until I changed the dll version from 16.0.0.0 to 15.0.0.0 Thanks! Sep 19 '16 at 13:51
0

Is this question still actual? Cause you just need to generate a right XML to be imported via ImportWebPart method.

2
  • Big issue at the time was setting the calendar view. Added list webparts generate their own view, ignoring the one provided in the XML.
    – Oaden
    Aug 19 '14 at 11:35
  • Could you please describe the case? We do all stuff via code based provision, curious to address this 'calendar' provision issue as well.
    – user656
    Aug 20 '14 at 0:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.