Beispiel #1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var ctx = base.Context;

            XmlDocument viewSchema = null;

            if (ViewSchema != null)
            {
                viewSchema = ViewSchema.Read();
            }
            if (string.IsNullOrEmpty(ViewTitle) && viewSchema == null)
            {
                throw new ArgumentException("You must specify a value for at least one of the ViewTitle or ViewSchema parameters.");
            }
            var     web    = ctx.Site.OpenWeb(Web.Read());
            SPOFile file   = File.Read(web);
            SPOList list   = List.Read(web, true);
            Guid    viewId = Guid.Empty;

            if (!string.IsNullOrEmpty(ViewTitle))
            {
                var view = list.GetViews().Where(v => v.Title.ToLowerInvariant() == ViewTitle.ToLowerInvariant()).FirstOrDefault();
                if (view == null)
                {
                    throw new ArgumentException("The value specified for the ViewTitle parameter does not match an existing view.");
                }
            }

            string xml = GetXsltListViewWebPartXml(list.Id, list.Url, viewId, viewSchema, file.ServerRelativeUrl, Title, JSLink, ChromeType);

            if (list.BaseTemplate == 106)
            {
                if (viewSchema == null)
                {
                    var view = list.GetViews().Where(v => v.Title.ToLowerInvariant() == ViewTitle.ToLowerInvariant()).FirstOrDefault();
                    viewSchema = new XmlDocument();
                    viewSchema.LoadXml(view.ListViewXml);
                }
                xml = GetListViewWebPartXml(list.Id, list.Url, viewSchema, file.ServerRelativeUrl, Title, ChromeType);
            }
            if (ParameterSetName == "WikiPage")
            {
                SPOWikiPage wikiPage = file as SPOWikiPage;
                if (wikiPage == null)
                {
                    throw new Exception("The specified file is either not found or is not a wiki page.");
                }
                WriteObject(wikiPage.AddWebPartToWikiPage(xml, Title, Row, Column, AddSpace));
            }
            else
            {
                WriteObject(file.AddWebPartToWebPartPage(xml, Zone, ZoneIndex, Title));
            }
        }
Beispiel #2
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            var ctx = base.Context;

            string  xml  = WebPart.Read().OuterXml;
            var     web  = ctx.Site.OpenWeb(Web.Read());
            SPOFile file = File.Read(web);

            if (ParameterSetName == "WikiPage")
            {
                SPOWikiPage wikiPage = file as SPOWikiPage;
                if (wikiPage == null)
                {
                    throw new Exception("The specified file is either not found or is not a wiki page.");
                }
                WriteObject(wikiPage.AddWebPartToWikiPage(xml, Title, Row, Column, AddSpace));
            }
            else
            {
                WriteObject(file.AddWebPartToWebPartPage(xml, Zone, ZoneIndex, Title));
            }
        }