Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some web part provision on wiki page give empty markup #693

Closed
SubPointSupport opened this issue Oct 8, 2015 · 0 comments
Closed

Some web part provision on wiki page give empty markup #693

SubPointSupport opened this issue Oct 8, 2015 · 0 comments

Comments

@SubPointSupport
Copy link
Contributor

The following sample give en empty wiki page markup while the web part presents on the page.

The following web parts are affected:

  • ScriptEditorWebPart
  • ListViewWebPart

There might be more as well, need to be checked.

using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using Microsoft.SharePoint;
using SPMeta2.BuiltInDefinitions;
using SPMeta2.Definitions;
using SPMeta2.Definitions.Webparts;
using SPMeta2.Enumerations;
using SPMeta2.Services;
using SPMeta2.SSOM.DefaultSyntax;
using SPMeta2.SSOM.Standard.Services;
using SPMeta2.Syntax.Default;

namespace listviewwebparttest
{
    class Program
    {
        static void Main(string[] args)
        {
            var consoleUtils = new ConsoleUtils();

            consoleUtils.WithSSOMContext(args[0], (site, web) =>
            {
                var ssomProvisionService = new StandardSSOMProvisionService();
                consoleUtils.TraceDeploymentProgress(ssomProvisionService);

                var model = SPMeta2Model.NewWebModel(webM =>
                {
                    ListDefinition annualReviewsLibrary = new ListDefinition
                    {
                        Title = "Annual Reviews",
                        Description = "A document library.",
                        TemplateType = BuiltInListTemplateTypeId.DocumentLibrary,
                        Url = "m2AnnualReviews"
                    };

                    ListViewDefinition pool = new ListViewDefinition
                    {
                        Title = "Test",
                        Fields = new Collection<string>
                        {
                            BuiltInInternalFieldNames.ID,
                            BuiltInInternalFieldNames.Title
                        }
                    };

                    ListViewWebPartDefinition listView = new ListViewWebPartDefinition
                    {
                        Title = "Annual Reviews Default View by List Url",
                        Id = "m2AnnualReviewsView",
                        ZoneIndex = 10,
                        ZoneId = "Main",
                        ListUrl = annualReviewsLibrary.GetListUrl(),
                        ViewName = pool.Title
                    };

                    WikiPageDefinition pageFacilityManagementTickets = new WikiPageDefinition
                    {
                        Title = PageNames.FacilityTicket,
                        FileName = PageNames.FacilityTicket + ".aspx"
                    };

                    webM.AddList(annualReviewsLibrary, list =>
                    {
                        list.AddListView(pool);
                    });

                    webM.AddHostList(BuiltInListDefinitions.SitePages, list =>
                    {
                        list.AddWikiPage(pageFacilityManagementTickets, f =>
                        {
                            f.AddListViewWebPart(listView);

                        });

                    });
                });

                ssomProvisionService.DeployModel(SPMeta2.SSOM.ModelHosts.WebModelHost.FromWeb(web), model);
            });
        }
    }

    public partial class ConsoleUtils
    {
        public virtual void TraceDeploymentProgress(ProvisionServiceBase provisionService)
        {
            provisionService.OnModelNodeProcessed += (sender, args) =>
            {
                Console.WriteLine(string.Empty);
                Console.WriteLine(string.Empty);

                var message = string.Format("Processed: [{0}/{1}] - [{2:00.0} %] - [{3}] [{4}]",
                    new object[]
                    {
                        args.ProcessedModelNodeCount,
                        args.TotalModelNodeCount,
                        100d*(double) args.ProcessedModelNodeCount/(double) args.TotalModelNodeCount,
                        args.CurrentNode.Value.GetType().Name,
                        args.CurrentNode.Value
                    });

                Trace.WriteLine(message);
                Console.WriteLine(message);
            };
        }
    }
    public partial class ConsoleUtils
    {
        public virtual void WithSSOMContext(string siteUrl, Action<SPSite, SPWeb> action)
        {
            // just a little check on URL, saves some typos
            new Uri(siteUrl);

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (var site = new SPSite(siteUrl))
                {
                    using (var web = site.OpenWeb())
                    {
                        action(site, web);
                    }
                }
            });
        }
    }

    public static class PageNames
    {
        public const string FacilityTicket = "Facility Management Tickets";
    }
}

@SubPointSupport SubPointSupport self-assigned this Oct 8, 2015
@SubPointSupport SubPointSupport changed the title LIstViewWebPart provision on wiki page give empty markup Some web part provision on wiki page give empty markup Oct 23, 2015
SubPointSupport added a commit that referenced this issue Oct 23, 2015
…e wiki pages - Some web part provision on wiki page give empty markup #693
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant