1

I want to add a calendar view to a page, in the XML I have ViewGuid but it does not work. How can I achieve this goal?

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>{0}</Title>
  <FrameType>Default</FrameType>
  <IsIncluded>true</IsIncluded>
  <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>
  <HelpLink />
  <HelpMode>Navigate</HelpMode>
  <Dir>Default</Dir>
  <PartImageSmall />
  <MissingAssembly>No se puede importar este elemento web.</MissingAssembly>
  <PartImageLarge>/_layouts/15/images/itgen.png?rev=38</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>
  <ViewGuid>{1}</ViewGuid>
  <ListId xmlns="http://schemas.microsoft.com/WebPart/v2/ListView">{2}</ListId>
  <ViewFlag xmlns="http://schemas.microsoft.com/WebPart/v2/ListView">2633740</ViewFlag>
  <ViewFlags xmlns="http://schemas.microsoft.com/WebPart/v2/ListView">TabularView Hidden Recursive RecurrenceRowset Calendar FilesOnly</ViewFlags>
  <ViewContentTypeId xmlns="http://schemas.microsoft.com/WebPart/v2/ListView">0x</ViewContentTypeId>
</WebPart>

Method

public static void AddWebpartToWebPartPage(ClientContext clientContext, File page, string zonaName, int zonaIndex, string webPartContent)
    {
        page.CheckOut();
        LimitedWebPartManager wpmgr = page.GetLimitedWebPartManager(PersonalizationScope.Shared);
        WebPartDefinition wpd = wpmgr.ImportWebPart(webPartContent);
        wpmgr.AddWebPart(wpd.WebPart, zonaName, zonaIndex);
        page.CheckIn(String.Empty, CheckinType.MajorCheckIn);
        page.Publish(string.Empty);
        clientContext.ExecuteQuery();
    }

Use

Microsoft.SharePoint.Client.File DisponibilidadDeCabañas = Helpers.CreatePublishingPage(cc, "DisponibilidadDeCabanas", "SPC2Cols");
    webpart = System.IO.File.ReadAllText(System.Web.Hosting.HostingEnvironment.MapPath(string.Format("~/Template/{0}.webpart", "Calendar")));
    webpartContent = string.Format(webpart, "Hotel 1", "db60157c-f062-4114-9017-2db375a31a54", reservaDeCabanasId);
    Helpers.AddWebpartToWebPartPage(cc, DisponibilidadDeCabañas, "x8cad2e6659ff4dedb066f7fcd0d2c8ca", 0, webpartContent);

    webpartContent = string.Format(webpart, "Hotel 2", "0ca84683-8d90-4cbd-841e-76016b379099", reservaDeCabanasId);
    Helpers.AddWebpartToWebPartPage(cc, DisponibilidadDeCabañas, "x8cad2e6659ff4dedb066f7fcd0d2c8ca", 1, webpartContent);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.