I have a custom Pagelayout, I wan't to add a EventList and will show the Calendar View for this.
But when I use the follwing code in the custom pagelayout it only show a plain list.
<WebPartPages:XsltListViewWebPart ID="calendarmaintenance" runat="server" ListUrl="Lists/ServiceCalendar" IsIncluded="True" NoDefaultStyle="TRUE" Title="Public Documents" PageType="PAGE_NORMALVIEW" FrameType="None" Default="False" ViewContentTypeId="0x">
<XmlDefinition>
<View BaseViewID="2" Type="CALENDAR" WebPartZoneID="Main" DisplayName="$Resources:core,userinfo_schema_calendarview;" MobileView="TRUE" MobileDefaultView="TRUE"
SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/15/images/events.png?rev=23" TabularView="FALSE" Url="calendar.aspx" RecurrenceRowset="TRUE" DefaultView="TRUE"
MobileUrl="_layouts/15/mobile/viewdaily.aspx">
<Toolbar Type="None" />
<ParameterBindings>
<ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
<ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
</ParameterBindings>
<ViewFields>
</ViewFields>
<ViewData>
<FieldRef Name="Location" Type="CalendarWeekLocation"/>
<Query>
</Query>
</View>
</XmlDefinition>
</WebPartPages:XsltListViewWebPart>
I also Tried to adding a ListViewWebpart onto the Page in a webpart zone with follwing code:
ListViewWebPart calendar = new ListViewWebPart();
calendar.ListId = list.ID;
foreach (SPView view in list.Views)
{
if (view.Url.ToString().Contains(urlviewpagename))
{
SharePointLogger.Log($"Found view {urlviewpagename}");
calendar.ID = Guid.NewGuid().ToString("B").ToUpperInvariant();
calendar.ViewGuid = view.ID.ToString("B").ToUpperInvariant();
}
}
calendar.ChromeState = PartChromeState.Normal;
calendar.ChromeType = PartChromeType.TitleOnly;
SharePointLogger.LogInformation($"Adding {list.Title} to zone {zoneid}");
webpartManager.AddWebPart(calendar, zoneid, 0);
This dispaly the Calendar but it does throw many javascript exceptions and I also have a deactivated ribbon bar to. What do I wrong? :(