private static Dictionary <string, string> GetProperties(ISharePointCommandContext context, PublishingPageInfo pageInfo)
        {
            Dictionary <string, string> pageProperties = new Dictionary <string, string>();

            PublishingWeb  publishingWeb = PublishingWeb.GetPublishingWeb(context.Web);
            PublishingPage page          = publishingWeb.GetPublishingPage(pageInfo.ServerRelativeUrl);

            if (page != null)
            {
                pageProperties = SharePointCommandServices.GetProperties(page);
            }

            return(pageProperties);
        }
        private static string ExportToXml(ISharePointCommandContext context, PublishingPageInfo pageInfo)
        {
            string pageXml = null;

            PublishingWeb  publishingWeb = PublishingWeb.GetPublishingWeb(context.Web);
            PublishingPage page          = publishingWeb.GetPublishingPage(pageInfo.ServerRelativeUrl);

            if (page != null)
            {
                pageXml = ExportPublishingPage(page, context.Web, context).ToString();
            }

            return(pageXml);
        }
        protected override IEnumerable <PublishingPage> RetrieveDataObjects()
        {
            List <PublishingPage> publishingPages = new List <PublishingPage>();

            switch (ParameterSetName)
            {
            case "SPWeb":
                foreach (SPWebPipeBind webPipe in Web)
                {
                    SPWeb web = webPipe.Read();

                    WriteVerbose("Getting publishing page from " + web.Url);
                    if (!PublishingWeb.IsPublishingWeb(web))
                    {
                        WriteWarning(string.Format("Web \"{0}\" is not a publishing web and will be skipped.", web.Url));
                        continue;
                    }
                    PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);


                    if (PageName == null || PageName.Length == 0)
                    {
                        foreach (PublishingPage page in pubWeb.GetPublishingPages())
                        {
                            publishingPages.Add(page);
                        }
                    }
                    else
                    {
                        foreach (string pageName in PageName)
                        {
                            string pageUrl = string.Format("{0}/{1}/{2}", web.Url.TrimEnd('/'), pubWeb.PagesListName, pageName.Trim('/'));

                            try
                            {
                                PublishingPage page = pubWeb.GetPublishingPage(pageUrl);
                                if (page != null)
                                {
                                    publishingPages.Add(page);
                                }
                                else
                                {
                                    WriteWarning("Could not locate the specified page: " + pageUrl);
                                }
                            }
                            catch (ArgumentException)
                            {
                                WriteWarning("Could not locate the specified page: " + pageUrl);
                            }
                        }
                    }
                }
                break;

            case "SPFile":
                foreach (SPFilePipeBind filePipe in Identity)
                {
                    SPFile file = filePipe.Read();
                    if (!PublishingWeb.IsPublishingWeb(file.Web))
                    {
                        WriteWarning(string.Format("Web \"{0}\" is not a publishing web and will be skipped.", file.Web.Url));
                        continue;
                    }

                    WriteVerbose("Getting publishing page from " + file.Url);
                    try
                    {
                        PublishingPage page = null;
                        if (file.Exists)
                        {
                            page = PublishingPage.GetPublishingPage(file.Item);
                        }

                        if (page != null)
                        {
                            publishingPages.Add(page);
                        }
                        else
                        {
                            WriteWarning("Could not locate the specified page: " + file.Url);
                        }
                    }
                    catch (ArgumentException)
                    {
                        WriteWarning("Could not locate the specified page: " + file.Url);
                    }
                }
                break;
            }

            foreach (PublishingPage page in publishingPages)
            {
                AssignmentCollection.Add(page.PublishingWeb.Web);
                AssignmentCollection.Add(page.PublishingWeb.Web.Site);
                WriteResult(page);
            }

            return(null);
        }