/// <summary>
        /// A site was provisioned.
        /// </summary>
        public override void WebProvisioned(SPWebEventProperties properties)
        {
            base.WebProvisioned(properties);
            SPSite siteCollection = properties.Web.Site;
            SPWeb  subSite        = properties.Web;

            if (!subSite.WebTemplate.Contains("APP"))
            {
                Guid sitePublishingGuid = new Guid("f6924d36-2fa8-4f0b-b16d-06b7250180fa");
                Guid webPublishingGuid  = new Guid("94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb");

                EnsureSiteFeatureActivated(sitePublishingGuid, siteCollection);
                EnsureWebFeatureActivated(webPublishingGuid, siteCollection, subSite);

                var pubWeb = PublishingWeb.GetPublishingWeb(subSite);
                var webNavigationSettings = new Microsoft.SharePoint.Publishing.Navigation.WebNavigationSettings(subSite);
                webNavigationSettings.GlobalNavigation.Source  = Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource.InheritFromParentWeb;
                webNavigationSettings.CurrentNavigation.Source = Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource.PortalProvider;
                webNavigationSettings.Update();
                pubWeb.Update();

                subSite.MasterUrl       = siteCollection.RootWeb.MasterUrl;
                subSite.CustomMasterUrl = siteCollection.RootWeb.CustomMasterUrl;
                subSite.SiteLogoUrl     = siteCollection.RootWeb.SiteLogoUrl;
                subSite.Update();
            }
        }
Example #2
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;

            PublishingWeb pWeb           = PublishingWeb.GetPublishingWeb(site.RootWeb);
            bool          pageNotCreated = !pWeb.GetPublishingPages().Cast <PublishingPage>().Any(p => p.Name == pageName);

            if (pageNotCreated)
            {
                //если такой страницы еще нет - создаем ее
                PublishingPage pPage = pWeb.GetPublishingPages().Add(pageName, null);

                pPage.CheckOut();

                using (Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager wpManager = site.RootWeb.GetLimitedWebPartManager(pPage.Url, PersonalizationScope.Shared))
                {
                    ResultScriptWebPart searchResults = GetImportedWebPart(site, wpName) as ResultScriptWebPart;
                    searchResults.Title      = wpTitle;
                    searchResults.ChromeType = PartChromeType.None;

                    wpManager.AddWebPart(searchResults, "Top", 0);
                }

                pPage.CheckIn(string.Empty);
            }
        }
Example #3
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb web = properties.Feature.Parent as SPWeb;

            //if the web of type MLGSchool, set its MasterURL and Custom MasterURl
            if (string.Compare(web.WebTemplate, "MLGSchool", true) == 0)
            {
                try
                {
                    string masterURL = web.ServerRelativeUrl + masterPageName;
                    web.MasterUrl       = masterURL;
                    web.CustomMasterUrl = masterURL;
                    web.Update();
                }
                catch { }
            }
            else
            {
                //in case this is not a school site, check if it is a publishing web,
                //and if so set the MasterURL, and customMusterURl to inherit from the parent site.
                try
                {
                    if (PublishingWeb.IsPublishingWeb(web))
                    {
                        PublishingWeb pWeb = PublishingWeb.GetPublishingWeb(web);
                        pWeb.MasterUrl.SetInherit(true, true);
                        pWeb.CustomMasterUrl.SetInherit(true, true);
                        pWeb.Update();
                    }
                }
                catch { }
            }
        }
Example #4
0
        private void CreatePartnerTabbedPage(SPWeb web, SPList sitesList)
        {
            // Create a new page for listing Partner Site Collections
            if (PublishingWeb.IsPublishingWeb(web))
            {
                PublishingWeb            pubWeb           = PublishingWeb.GetPublishingWeb(web);
                PublishingPageCollection availablePages   = pubWeb.GetPublishingPages();
                PublishingPage           partnerSitesPage = availablePages[Constants.PartnerSitesPageUrl];

                if (partnerSitesPage == null)
                {
                    // The Partner Sites page should be based on the same layout as the top sites page.
                    PublishingPage topSitesPage = availablePages[Constants.TopSitesPageUrl];
                    partnerSitesPage = availablePages.Add(Constants.PartnerSitesFileName, topSitesPage.Layout);
                    partnerSitesPage.ListItem[titleFieldId] = Constants.PartnerSitesTile;
                    // We can not use the Field Id of the the Description field, because it is not static.
                    partnerSitesPage.ListItem[Constants.DescriptionField] = Resources.PartnerSitePageDescription;
                    partnerSitesPage.Update();
                    SPFile partnerSitesPageFile = web.GetFile(partnerSitesPage.Url);

                    AddListViewWebPartToPage(sitesList, partnerSitesPage, partnerSitesPageFile);

                    // Add a tab to the Tabs control.
                    SPListItem newTab = web.Lists[Constants.TabsList].Items.Add();
                    newTab[Constants.TabNameField] = Constants.PartnersTabName;
                    newTab[Constants.PageField]    = Constants.PartnerSitesFileName;
                    newTab[Constants.TooltipField] = Constants.PartnerSitesTooltip;
                    newTab.Update();
                }
            }
        }
Example #5
0
        // Uncomment the method below to handle the event raised before a feature is deactivated.

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPSite siteCollection = properties.Feature.Parent as SPSite;

            if (siteCollection != null)
            {
                SPWeb  topLevelSite       = siteCollection.RootWeb;
                String WebAppRelativePath = topLevelSite.ServerRelativeUrl;
                if (!WebAppRelativePath.EndsWith("/"))
                {
                    WebAppRelativePath += "/";
                }
                foreach (SPWeb site in siteCollection.AllWebs)
                {
                    if (!site.WebTemplate.Contains("APP"))
                    {
                        var pubWeb = PublishingWeb.GetPublishingWeb(site);
                        var webNavigationSettings = new Microsoft.SharePoint.Publishing.Navigation.WebNavigationSettings(site);
                        webNavigationSettings.GlobalNavigation.Source  = Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource.PortalProvider;
                        webNavigationSettings.CurrentNavigation.Source = Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource.PortalProvider;
                        webNavigationSettings.Update();
                        pubWeb.Update();
                        site.MasterUrl       = WebAppRelativePath + "_catalogs/masterpage/seattle.master";
                        site.CustomMasterUrl = WebAppRelativePath + "_catalogs/masterpage/seattle.master";
                        site.SiteLogoUrl     = "";
                        site.Update();
                    }
                }
            }
        }
        private void DeployDefinition(object modelHost, WebModelHost webModelHost, PageLayoutAndSiteTemplateSettingsDefinition definition)
        {
            var web           = webModelHost.HostWeb;
            var publishingWeb = PublishingWeb.GetPublishingWeb(web);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = web,
                ObjectType       = typeof(SPWeb),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });

            ProcessWebTemplateSettings(publishingWeb, definition);
            ProcessPageLayoutSettings(publishingWeb, definition);
            ProcessNewPageDefaultSettings(publishingWeb, definition);
            ProcessConverBlankSpacesIntoHyphenSetting(publishingWeb, definition);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = web,
                ObjectType       = typeof(SPWeb),
                ObjectDefinition = definition,
                ModelHost        = modelHost
            });

            publishingWeb.Update();
        }
        protected override IEnumerable <PageLayout> RetrieveDataObjects()
        {
            List <PageLayout> layouts = new List <PageLayout>();

            SPWeb web = null;

            if (Web != null)
            {
                web = Web.Read();

                if (!PublishingWeb.IsPublishingWeb(web))
                {
                    throw new ArgumentException("The specified web is not a publishing web.");
                }

                AssignmentCollection.Add(web);
                AssignmentCollection.Add(web.Site);
            }

            switch (ParameterSetName)
            {
            case "PageLayout":
                foreach (SPPageLayoutPipeBind pipeBind in PageLayout)
                {
                    PageLayout    layout = pipeBind.Read(web);
                    SPContentType ct1    = null;
                    if (AssociatedContentType != null)
                    {
                        ct1 = AssociatedContentType.Read(layout.ListItem.Web);
                    }
                    if (ct1 == null || ct1.Id == layout.AssociatedContentType.Id)
                    {
                        WriteResult(layout);
                    }
                }
                break;

            case "SPWeb":
                PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);
                SPContentType ct2    = null;
                if (AssociatedContentType != null)
                {
                    ct2 = AssociatedContentType.Read(web);
                }
                if (ct2 == null)
                {
                    WriteResult(pubWeb.GetAvailablePageLayouts());
                }
                else
                {
                    WriteResult(pubWeb.GetAvailablePageLayouts(ct2.Id));
                }
                break;

            default:
                break;
            }

            return(null);
        }
Example #8
0
        /// <summary>
        /// Establece la Página de bienveniva de un sitiio
        /// </summary>
        /// <param name="web">Objeto SPWeb </param>
        /// <param name="welcomePage"> Url de la página de bienvenida</param>
        /// <returns></returns>
        public static bool SetWelcomePage(this SPWeb web, string welcomePage)
        {
            var result = true;

            try
            {
                if (PublishingWeb.IsPublishingWeb(web))
                {
                    var publishingWeb = PublishingWeb.GetPublishingWeb(web);
                    var homeFile      = web.GetFile(welcomePage);
                    publishingWeb.DefaultPage = homeFile;
                    publishingWeb.Update();
                }
                else
                {
                    web.RootFolder.WelcomePage = welcomePage;
                }
                web.Update();
            }
            catch (Exception)
            {
                result = false;
            }
            return(result);
        }
        private void PollPublishingWebActivated(string webUrl, int delay = 0)
        {
            bool poll = false;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                //TraceLogger.TraceInfo("Checking for PublishingWeb at '{0}' (attempt {1})", webUrl, attempt);
                using (SPSite site = new SPSite(webUrl))
                    using (SPWeb newWeb = site.OpenWeb())
                    {
                        if (PublishingWeb.IsPublishingWeb(newWeb))
                        {
                            PublishingSite pubSite = new PublishingSite(site);
                            var pubWeb             = PublishingWeb.GetPublishingWeb(newWeb);
                            SPList pages           = null;
                            try
                            {
                                pages = pubWeb.PagesList;
                            }
                            catch { }
                            if (pages != null)
                            {
                                pages.EnableModeration    = false;
                                pages.EnableVersioning    = true;
                                pages.EnableMinorVersions = false;
                                pages.MajorVersionLimit   = 5;
                                pages.ForceCheckout       = false;
                                pages.Update();
                            }

                            if (OnPublishingWebActivated != null)
                            {
                                OnPublishingWebActivated(newWeb, pubSite, pubWeb);
                            }
                            if (OnPublishingActivated != null)
                            {
                                OnPublishingActivated(webUrl);
                            }
                        }
                        else
                        {
                            //TraceLogger.TraceInfo("Web at '{0}' IS NOT a publishing Web (yet)!", webUrl);
                            poll = delay < PUBLISHING_MAX_DELAY;
                        }
                    }
            });

            if (poll)
            {
                Timer timer = new System.Timers.Timer(POLL_SPEED);
                timer.AutoReset = false;
                timer.Elapsed  += delegate
                {
                    PollPublishingWebActivated(webUrl, delay += POLL_SPEED);
                };
                timer.Enabled = true;
            }
        }
        // method for creating publising page
        private string CreatePublishingPage(string pageName, string pageLayoutName, bool isLandingPage)
        {
            string createdPageURL = string.Empty;

            // elevated privilages as not all user will have permission to create a new page
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                // get current web
                SPWeb oWeb                  = SPContext.Current.Web;
                string fullPageUrl          = string.Empty;
                PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(oWeb);
                /* Get the publishing web page collection list. */
                PublishingPageCollection publishingPageCollection = publishingWeb.GetPublishingPages();
                //GetPageLayoutName(application);
                if (!string.IsNullOrEmpty(pageLayoutName))
                {
                    /* Search for the page layout for creating the new page */
                    List <PageLayout> layouts = new List <PageLayout>(publishingWeb.GetAvailablePageLayouts());
                    PageLayout pageLayout     = layouts.Find(
                        delegate(PageLayout l)
                    {
                        return(l.Name.Equals(pageLayoutName, StringComparison.CurrentCultureIgnoreCase));
                    });
                    /*page layout exists*/
                    if (pageLayout != null)
                    {
                        PublishingPage newPage = null;
                        newPage       = publishingPageCollection.Add(pageName + ".aspx", pageLayout);
                        newPage.Title = pageName;
                        newPage.Update();

                        SPList li = newPage.ListItem.ParentList;

                        if (li.EnableModeration == false)
                        {
                            li.EnableModeration = true;
                            li.Update();
                        }
                        newPage.CheckIn("page checked in");
                        newPage.ListItem.File.Publish("page published");
                        newPage.ListItem.File.Approve("page approved");
                        /* Set newly created page as a welcome page */
                        if (isLandingPage == true)
                        {
                            fullPageUrl               = oWeb.Url + "/Pages/" + pageName + ".aspx";
                            SPFile fileNew            = publishingWeb.Web.GetFile(fullPageUrl);
                            publishingWeb.DefaultPage = fileNew;
                        }
                        publishingWeb.Update();

                        createdPageURL = newPage.Uri.AbsoluteUri.ToString();
                    }
                }
            });

            // return new page url
            return(createdPageURL);
        }
Example #11
0
        public static void AllowPageLayouts(SPSite site, bool allow, params string[] pageLayouts)
        {
            var publishingWeb = PublishingWeb.GetPublishingWeb(site.RootWeb);

            if (publishingWeb != null)
            {
                if (allow)
                {
                    var pageLayoutList = new ArrayList();
                    var pSite          = publishingWeb.Web.Site;
                    if (pSite != null)
                    {
                        var publishingSite        = new PublishingSite(pSite);
                        var pageLayoutsCollection = publishingSite.GetPageLayouts(true);
                        foreach (var pl in pageLayoutsCollection)
                        {
                            if (
                                pageLayouts.ToList()
                                .Any(p => pl.ServerRelativeUrl.ToLower().Contains(p.ToLower())))
                            {
                                pageLayoutList.Add(pl);
                            }
                        }
                        var newPls = (PageLayout[])pageLayoutList.ToArray(typeof(PageLayout));
                        publishingWeb.SetAvailablePageLayouts(newPls, false);
                        publishingWeb.Update();
                    }
                }
                else
                {
                    var availablePageLayouts = publishingWeb.GetAvailablePageLayouts();
                    var pageLayoutList       = new ArrayList();
                    pageLayoutList.AddRange(availablePageLayouts);
                    var pSite = publishingWeb.Web.Site;
                    if (pSite != null)
                    {
                        var publishingSite        = new PublishingSite(pSite);
                        var pageLayoutsCollection = publishingSite.GetPageLayouts(true);
                        foreach (PageLayout pl in pageLayoutsCollection)
                        {
                            if (
                                pageLayouts.ToList()
                                .Any(p => pl.ServerRelativeUrl.ToLower().Contains(p.ToLower())))
                            {
                                if (pageLayoutList.Contains(pl))
                                {
                                    pageLayoutList.Remove(pl);
                                }
                            }
                        }

                        var newPls = (PageLayout[])pageLayoutList.ToArray(typeof(PageLayout));
                        publishingWeb.SetAvailablePageLayouts(newPls, false);
                        publishingWeb.Update();
                    }
                }
            }
        }
        private void AddResultsForSPWeb(SPSite site, SPWeb web)
        {
            WBLogging.RecordsTypes.Verbose("In AddResultsForSPWeb(): looking at SPWeb: " + web.Url);


            try
            {
                PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);

                foreach (PublishingPage page in pubWeb.GetPublishingPages())
                {
                    WBLogging.RecordsTypes.Verbose("In AddResultsForSPWeb(): page = " + page.WBxToString());

                    if (page != null)
                    {
                        AddResultsForPublishingPage(page);

                        WBLogging.RecordsTypes.Verbose("InAddResultsForSPWeb() just finished for AddResultsForPublishingPage(): page = " + page.Name);
                    }
                }
            }
            catch (Exception e)
            {
                WBLogging.RecordsTypes.Verbose("In FindWhereRecordIsBeingUsed.AddResultsForSPWeb(): This SPWeb is probably not a publishing site: " + web.Url);

                StringBuilder command = new StringBuilder();
                command.Append("<script type=\"text/javascript\">errorProcessingPage(\"").Append(web.Url).Append("\", \"An exception occured at an SPWeb level: ").Append(e.Message).Append("\");</script>\n");
                command.Append("<!-- Full exception stack using ToString(): ");
                command.Append(e.ToString()).Append("-->\n\n");

                command.Append("<!-- Full exception stack using FlattenException(): ");
                command.Append(FlattenException(e)).Append("-->\n\n");

                Response.Write(command.ToString());
                Response.Flush();
            }

            WBLogging.RecordsTypes.Verbose("InAddResultsForSPWeb() about to look at sub webs for SPWeb: " + web.Url);

            foreach (SPWeb subWeb in web.Webs)
            {
                if (subWeb != null)
                {
                    WBLogging.RecordsTypes.Verbose("InAddResultsForSPWeb() for a sub SPWeb: " + subWeb.Url);

                    AddResultsForSPWeb(site, subWeb);

                    WBLogging.RecordsTypes.Verbose("InAddResultsForSPWeb() returned from AddResultsForSPWeb for:" + subWeb.Url);

                    subWeb.Dispose();
                }
                else
                {
                    WBLogging.RecordsTypes.Verbose("InAddResultsForSPWeb() subweb was null:");
                }
            }
        }
Example #13
0
        public static void EnsurePublishingWorkflows(SPWeb web, bool useSAMLWorkflow, bool remove)
        {
            if (PublishingWeb.IsPublishingWeb(web))
            {
                PublishingWeb pubweb = PublishingWeb.GetPublishingWeb(web);

                if (pubweb != null)
                {
                    string listNames = GlobalSettingsHelper.GetValue(ListConstants.EnablePublishingApprovalWorkflowOnLists);

                    if (!string.IsNullOrEmpty(listNames))
                    {
                        string[] lists = listNames.ToLower().Split(new char[] { ',' });
                        foreach (string listName in lists)
                        {
                            SPList list = null;
                            switch (listName)
                            {
                            case ("pages"):
                                list = pubweb.PagesList;
                                break;

                            case ("images"):
                                list = pubweb.ImagesLibrary;
                                break;

                            case ("documents"):
                                list = pubweb.DocumentsLibrary;
                                break;
                            }

                            if (list != null)
                            {
                                if (remove)
                                {
                                    WorkflowHelper2013.RemoveApprovalWorkflowOnList(web, list, useSAMLWorkflow);
                                }
                                else
                                {
                                    List <WorkflowHelper2013.WorkflowStartEventType> events = new List <WorkflowHelper2013.WorkflowStartEventType>()
                                    {
                                        WorkflowHelper2013.WorkflowStartEventType.Manual
                                    };

                                    WorkflowHelper2013.EnsureApprovalWorkflowOnList(web, list, events, useSAMLWorkflow);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                throw new SPException("This feature can only be enabled on a Publishing Web. However you can configure the approval workflows thru list workflow settings.");
            }
        }
    public static void CreatePublishingPage(ClientContext ctx, string pageName, string pageLayoutName)
    {
        var pubWeb   = PublishingWeb.GetPublishingWeb(ctx, ctx.Web);
        var pageInfo = new PublishingPageInformation();

        pageInfo.Name = pageName;
        pageInfo.PageLayoutListItem = GetPageLayout(ctx, pageLayoutName);
        var publishingPage = pubWeb.AddPublishingPage(pageInfo);

        ctx.ExecuteQuery();
    }
Example #15
0
 public List <string> GetAllPagesInWeb(SPWeb web)
 {
     if (PublishingWeb.IsPublishingWeb(web))
     {
         return(GetAllPublishingPages(PublishingWeb.GetPublishingWeb(web)));
     }
     else
     {
         return(GetAllPagesFromRoot(web));
     }
 }
Example #16
0
        private void InitializeObject(SPWeb web)
        {
            SPSite cachedSuperUserSite = null;

            if (HttpContext.Current != null)
            {
                cachedSuperUserSite = HttpContext.Current.Items["SuperUserSite"] as SPSite;
                if (cachedSuperUserSite != null && cachedSuperUserSite.ID != web.Site.ID)
                {
                    HttpContext.Current.Items["SuperUserSite"] = null;
                }
            }
            try {
                if (PublishingWeb.IsPublishingWeb(web))
                {
                    PublishingWeb  currentWeb   = PublishingWeb.GetPublishingWeb(web);
                    VariationLabel currentLabel = GetVariationLabel(currentWeb);
                    if (currentLabel != null)
                    {
                        this.IsVariationWeb          = true;
                        this.IsSource                = currentLabel.IsSource;
                        this.TopWebServerRelativeUrl = new Uri(currentLabel.TopWebUrl).AbsolutePath;
                        this.VariationLabel          = currentLabel.Title;
                        this.PagesListName           = currentWeb.PagesListName;
                        int lcid;
                        if (Int32.TryParse(currentLabel.Locale, out lcid))
                        {
                            this.Culture = CultureInfo.GetCultureInfo(lcid);
                        }
                        else
                        {
                            this.Culture = CultureInfo.GetCultureInfo(currentLabel.Language);
                        }
                    }
                }
                if (!this.IsVariationWeb)
                {
                    this.TopWebServerRelativeUrl = web.Site.ServerRelativeUrl;
                    this.VariationLabel          = String.Empty;
                    this.PagesListName           = "Pages";
                    this.Culture = web.UICulture;
                }
            } finally {
                // avoid messing up calls to publishing web API in the same HTTP request (FileNotFoundException)
                // where SuperUserSite should be reserved for current site collection
                // https://sharepoint.stackexchange.com/questions/83242
                if (HttpContext.Current != null && (cachedSuperUserSite == null || cachedSuperUserSite.ID != web.Site.ID))
                {
                    HttpContext.Current.Items["SuperUserSite"] = cachedSuperUserSite;
                }
            }
        }
Example #17
0
        /// <summary>
        /// Creates the publishing page asynchronous.
        /// </summary>
        /// <param name="layoutRelativeUrl">The layout relative URL.</param>
        /// <param name="pageNameWithExtension">The page name with extension.</param>
        /// <returns></returns>
        public async Task <PublishingPage> CreatePublishingPageAsync(string layoutRelativeUrl, string pageNameWithExtension)
        {
            var layoutItem = await GetPageLayoutItemAsync(layoutRelativeUrl);

            var publishingWeb = PublishingWeb.GetPublishingWeb(_ctx, _web);
            var page          = publishingWeb.AddPublishingPage(new PublishingPageInformation
            {
                Name = pageNameWithExtension,
                PageLayoutListItem = layoutItem
            });
            await _ctx.ExecuteQueryAsync();

            return(page);
        }
Example #18
0
        public static void CreatePublishingPage(ClientContext clientContext, string pageName, string pagelayoutname, string url, string queryurl)
        {
            var publishingPageName = pageName + ".aspx";

            Web web = clientContext.Web;

            clientContext.Load(web);

            List pages = web.Lists.GetByTitle("Pages");

            clientContext.Load(pages.RootFolder, f => f.ServerRelativeUrl);
            clientContext.ExecuteQuery();

            Microsoft.SharePoint.Client.File file =
                web.GetFileByServerRelativeUrl(pages.RootFolder.ServerRelativeUrl + "/" + pageName + ".aspx");
            clientContext.Load(file, f => f.Exists);
            clientContext.ExecuteQuery();
            if (file.Exists)
            {
                file.DeleteObject();
                clientContext.ExecuteQuery();
            }
            PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(clientContext, web);

            clientContext.Load(publishingWeb);

            if (publishingWeb != null)
            {
                List publishingLayouts = clientContext.Site.RootWeb.Lists.GetByTitle("Master Page Gallery");

                ListItemCollection allItems = publishingLayouts.GetItems(CamlQuery.CreateAllItemsQuery());
                clientContext.Load(allItems, items => items.Include(item => item.DisplayName).Where(obj => obj.DisplayName == pagelayoutname));
                clientContext.ExecuteQuery();

                ListItem layout = allItems.Where(x => x.DisplayName == pagelayoutname).FirstOrDefault();
                clientContext.Load(layout);

                PublishingPageInformation publishingpageInfo = new PublishingPageInformation()
                {
                    Name = publishingPageName,
                    PageLayoutListItem = layout,
                };

                PublishingPage publishingPage = publishingWeb.AddPublishingPage(publishingpageInfo);
                publishingPage.ListItem.File.CheckIn(string.Empty, CheckinType.MajorCheckIn);
                publishingPage.ListItem.File.Publish(string.Empty);
                clientContext.ExecuteQuery();
            }
            SetSupportCaseContent(clientContext, "SupportCasesPage", url, queryurl);
        }
        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);
        }
        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);
        }
        public PageLayout Read(SPWeb web)
        {
            if (web == null)
            {
                return(Read((PublishingWeb)null));
            }

            if (!PublishingWeb.IsPublishingWeb(web))
            {
                throw new ArgumentException("The specified web is not a publishing web.");
            }
            PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);

            return(Read(pubWeb));
        }
        // this method gets all publishing pages for the web
        private List <string> GetAllPublishingPage()
        {
            List <string> pgList = new List <string>();

            SPWeb                    web                      = SPContext.Current.Web;
            string                   fullPageUrl              = string.Empty;
            PublishingWeb            publishingWeb            = PublishingWeb.GetPublishingWeb(web);
            PublishingPageCollection publishingPageCollection = publishingWeb.GetPublishingPages();
            List <PageLayout>        layouts                  = new List <PageLayout>(publishingWeb.GetAvailablePageLayouts());

            foreach (PageLayout pl in layouts)
            {
                pgList.Add(pl.Name);
            }

            return(pgList);
        }
        public static void GetNavigation(XmlDocument xmlDoc, SPWeb web, bool includeChildren)
        {
            if (PublishingWeb.IsPublishingWeb(web))
            {
                PublishingWeb pubweb  = PublishingWeb.GetPublishingWeb(web);
                XmlElement    webNode = (XmlElement)xmlDoc.DocumentElement.AppendChild(xmlDoc.CreateElement("Web"));
                webNode.SetAttribute("serverRelativeUrl", web.ServerRelativeUrl);

                GetNavigation(pubweb, webNode);
            }
            if (includeChildren)
            {
                foreach (SPWeb childWeb in web.Webs)
                {
                    GetNavigation(xmlDoc, childWeb, true);
                }
            }
        }
Example #24
0
        private static List <PublishingPageInfo> GetPublishingPages(ISharePointCommandContext context)
        {
            List <PublishingPageInfo> pages = new List <PublishingPageInfo>();

            PublishingWeb            publishingWeb   = PublishingWeb.GetPublishingWeb(context.Web);
            PublishingPageCollection publishingPages = publishingWeb.GetPublishingPages();

            pages = (from PublishingPage page
                     in publishingPages
                     select new PublishingPageInfo
            {
                Name = page.Name,
                ServerRelativeUrl = page.Uri.AbsolutePath,
                Title = page.Title,
            }).ToList();

            return(pages);
        }
        private PublishingWeb GetPublishingSiteFromWeb(SPWeb web)
        {
            PublishingWeb result = null;

            if (web == null)
            {
                throw new ArgumentNullException("web");
            }

            var pubSite = new PublishingSite(web.Site);

            if (PublishingWeb.IsPublishingWeb(web))
            {
                result = PublishingWeb.GetPublishingWeb(web);
            }

            return(result);
        }
Example #26
0
        // Uncomment the method below to handle the event raised after a feature has been activated.

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite siteCollection = properties.Feature.Parent as SPSite;

            if (siteCollection != null)
            {
                SPWeb topLevelSite = siteCollection.RootWeb;

                Guid sitePublishingGuid = new Guid("f6924d36-2fa8-4f0b-b16d-06b7250180fa");
                Guid webPublishingGuid  = new Guid("94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb");

                if (siteCollection.Features[sitePublishingGuid] == null)
                {
                    siteCollection.Features.Add(sitePublishingGuid);
                }
                String WebAppRelativePath = topLevelSite.ServerRelativeUrl;
                if (!WebAppRelativePath.EndsWith("/"))
                {
                    WebAppRelativePath += "/";
                }

                foreach (SPWeb site in siteCollection.AllWebs)
                {
                    if (!site.WebTemplate.Contains("APP"))
                    {
                        if (site.Features[webPublishingGuid] == null)
                        {
                            site.Features.Add(webPublishingGuid);
                        }
                        var pubWeb = PublishingWeb.GetPublishingWeb(site);
                        var webNavigationSettings = new Microsoft.SharePoint.Publishing.Navigation.WebNavigationSettings(site);
                        webNavigationSettings.GlobalNavigation.Source  = Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource.PortalProvider;
                        webNavigationSettings.CurrentNavigation.Source = Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource.PortalProvider;
                        webNavigationSettings.Update();
                        pubWeb.Update();
                        site.MasterUrl       = WebAppRelativePath + "_catalogs/masterpage/RivernetTeamSite.master";
                        site.CustomMasterUrl = WebAppRelativePath + "_catalogs/masterpage/RivernetTeamSite.master";
                        site.SiteLogoUrl     = WebAppRelativePath + "_layouts/15/images/RiverStonelogotransparent.png";
                        site.Update();
                    }
                }
            }
        }
Example #27
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb currentWeb = properties.Feature.Parent as SPWeb;

            // The Promotions feature should only be activated on a Publishing Site.
            if (PublishingWeb.IsPublishingWeb(currentWeb))
            {
                PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(currentWeb);
                SPFile        defaultPage   = publishingWeb.DefaultPage;
                // If the default page doesn't exist, it needs to be created first.
                if (defaultPage == null)
                {
                    defaultPage = CreateNewWelcomePage(currentWeb, publishingWeb, defaultPage);
                }
                else
                {
                    defaultPage.CheckOut();
                }

                try
                {
                    // Create a custom View that displays only Promotion Pages.
                    SPList pagesList          = currentWeb.Lists[PagesList];
                    SPView promotionsOnlyView = CreatePromotionsOnlyView(currentWeb, pagesList);

                    // Add a list view Web part to display Promotions Only
                    AddListViewWebPartToPage(defaultPage, pagesList, promotionsOnlyView);
                }
                finally
                {
                    defaultPage.CheckIn(CheckInComment);
                    defaultPage.Publish(CheckInComment);
                }

                // Save the URL of the site where this feature is being activated. This settings will be used at runtime.
                SetUrlInConfig(currentWeb);

                // Register the Promotion
                RegisterPromotionRepositoryTypeMapping();
            }
        }
Example #28
0
        public static OutputQueue SetLookoutAsMySiteHomePage(string mySiteWebUrl)
        {
            var output = new OutputQueue();

            try
            {
                using (var site = new SPSite(mySiteWebUrl))
                {
                    if (site != null)
                    {
                        using (var web = site.OpenWeb())
                        {
                            if (web != null)
                            {
                                if (PublishingWeb.IsPublishingWeb(web))
                                {
                                    var publishingWeb   = PublishingWeb.GetPublishingWeb(web);
                                    var lookoutPageFile = web.GetFile("Lookout.aspx");
                                    publishingWeb.DefaultPage = lookoutPageFile;
                                    publishingWeb.Update();
                                    publishingWeb.Close();
                                }
                                else
                                {
                                    var rootFolder = web.RootFolder;
                                    rootFolder.WelcomePage = "Lookout.aspx";
                                    rootFolder.Update();
                                    web.Update();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                output.Add(string.Format(CultureInfo.CurrentCulture, Exceptions.ErrorSettingLookoutHomePage, exception.Message), OutputType.Error, string.Empty, exception);
            }
            return(output);
        }
        /// <summary>
        /// Enumerates the specified web.
        /// </summary>
        /// <param name="site">The site.</param>
        /// <param name="web">The web.</param>
        /// <param name="enumerateSubWebs">if set to <c>true</c> [enumerate sub webs].</param>
        private void Enumerate(SPSite site, SPWeb web, bool enumerateSubWebs)
        {
            OnSPWebEnumerated(site, web);

            if (SPListEnumerated != null)
            {
                for (int i = 0; i < web.Lists.Count; i++)
                {
                    OnSPListEnumerated(site, web, web.Lists[i]);
                }
            }

#if MOSS
            if (PublishingPageEnumerated != null)
            {
                if (PublishingWeb.IsPublishingWeb(web))
                {
                    PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);
                    foreach (PublishingPage page in pubWeb.GetPublishingPages())
                    {
                        OnPublishingPageEnumerated(site, web, page);
                    }
                }
            }
#endif
            if (enumerateSubWebs)
            {
                foreach (SPWeb subWeb in web.Webs)
                {
                    try
                    {
                        Enumerate(site, subWeb, enumerateSubWebs);
                    }
                    finally
                    {
                        subWeb.Dispose();
                    }
                }
            }
        }
Example #30
0
        public void AddPublishingPage()
        {
            string pageName = "CustomPage3.aspx";
            Web    webSite  = context.Web;

            context.Load(webSite);
            PublishingWeb web = PublishingWeb.GetPublishingWeb(context, webSite);

            context.Load(web);

            if (web != null)
            {
                List pages = context.Site.RootWeb.Lists.GetByTitle("Pages");
                ListItemCollection defaultPages = pages.GetItems(CamlQuery.CreateAllItemsQuery());
                context.Load(defaultPages, items => items.Include(item => item.DisplayName).Where(obj => obj.DisplayName == pageName));
                context.ExecuteQuery();
                if (defaultPages != null && defaultPages.Count > 0)
                {
                }
                else
                {
                    List publishingLayouts      = context.Site.RootWeb.Lists.GetByTitle("Master Page Gallery");
                    ListItemCollection allItems = publishingLayouts.GetItems(CamlQuery.CreateAllItemsQuery());
                    context.Load(allItems, items => items.Include(item => item.DisplayName).Where(obj => obj.DisplayName == "PageLayoutTemplate"));
                    context.ExecuteQuery();
                    ListItem layout = allItems.Where(x => x.DisplayName == "PageLayoutTemplate").FirstOrDefault();
                    context.Load(layout);
                    PublishingPageInformation publishingPageInfo = new PublishingPageInformation();
                    publishingPageInfo.Name = pageName;
                    publishingPageInfo.PageLayoutListItem = layout;
                    PublishingPage publishingPage = web.AddPublishingPage(publishingPageInfo);
                    publishingPage.ListItem.File.CheckIn(string.Empty, CheckinType.MajorCheckIn);
                    publishingPage.ListItem.File.Publish(string.Empty);
                    publishingPage.ListItem.File.Approve(string.Empty);
                    context.Load(publishingPage);
                    context.Load(publishingPage.ListItem.File, obj => obj.ServerRelativeUrl);
                    context.ExecuteQuery();
                }
            }
        }