예제 #1
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);
            }
        }
 /// <summary>
 /// Update, check-in, publish and approve a page with a check-in message.
 /// </summary>
 /// <param name="page">The page.</param>
 /// <param name="message">The message.</param>
 public void UpdateCheckInPublishApprove(PublishingPage page, string message)
 {
     page.Update();
     page.CheckIn(message);
     page.ListItem.File.Publish(message);
     page.ListItem.File.Approve(message);
 }
        // 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);
        }
예제 #4
0
        private static void AddListViewWebPartToPage(SPList sitesList, PublishingPage partnerSitesPage, SPFile partnerSitesPageFile)
        {
            ListViewWebPart listViewWebPart = new ListViewWebPart();

            listViewWebPart.ViewType   = ViewType.None;
            listViewWebPart.ListName   = sitesList.ID.ToString("B").ToUpper(CultureInfo.CurrentCulture);
            listViewWebPart.ViewGuid   = sitesList.Views[Constants.PartnerSitesView].ID.ToString("B").ToUpper(CultureInfo.CurrentCulture);
            listViewWebPart.Title      = Constants.PartnerSitesTile;
            listViewWebPart.ChromeType = System.Web.UI.WebControls.WebParts.PartChromeType.None;

            SPLimitedWebPartManager webPartManager =
                partnerSitesPageFile.GetLimitedWebPartManager(System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);

            webPartManager.AddWebPart(listViewWebPart, Constants.LeftColumnZone, 1);
            webPartManager.Web.Dispose();
            partnerSitesPage.CheckIn(Constants.CheckInComment);
        }
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb web = properties.Feature.Parent as SPWeb;

            if (web != null)
            {
                if (PublishingWeb.IsPublishingWeb(web))
                {
                    PublishingWeb  pubWeb = PublishingWeb.GetPublishingWeb(web);
                    PublishingPage page   = pubWeb.GetPublishingPages()[PartnerLandingPageUrl];

                    if (page == null)
                    {
                        SPContentTypeId contentTypeId     = new SPContentTypeId(welcomePageLayoutContentTypeId);
                        PageLayout[]    layouts           = pubWeb.GetAvailablePageLayouts(contentTypeId);
                        PageLayout      welcomePageLayout = layouts[0];

                        page = pubWeb.GetPublishingPages().Add(PartnerLandingPageFileName, welcomePageLayout);
                    }
                    else
                    {
                        page.CheckOut();
                    }

                    page.ListItem[titleFieldId]                  = PartnerLandingPageTile;
                    page.ListItem[DescriptionField]              = Resources.PageDescription;
                    page.ListItem[pageContentFieldId]            = Resources.PageContent;
                    page.ListItem[partnerSpecificContentFieldId] = Resources.PartnerSpecificContent;
                    page.Update();

                    SPFile welcomeFile = web.GetFile(page.Url);
                    pubWeb.DefaultPage = welcomeFile;
                    pubWeb.Update();

                    page.CheckIn(Resources.CheckInValue);
                }
            }
        }
예제 #6
0
파일: SPHelper.cs 프로젝트: RaspeR87/sp-dev
        public static PublishingPage CreatePublishingPage(PublishingWeb CurrentPublishingWeb, string newPageName, PageLayout pageLayout, SPFolder folder, bool doCreateFriendlyUrl)
        {
            PublishingPage publishingPage = null;
            bool           tryNakedToken  = true;

            do
            {
                try
                {
                    if (doCreateFriendlyUrl)
                    {
                        newPageName = GetUniquePageName(newPageName, tryNakedToken, CurrentPublishingWeb, true, folder);
                    }
                    if (!newPageName.EndsWith(".aspx", StringComparison.OrdinalIgnoreCase))
                    {
                        newPageName += ".aspx";
                    }
                    publishingPage = ((folder != null) ? CurrentPublishingWeb.AddPublishingPage(newPageName, pageLayout, folder) : CurrentPublishingWeb.AddPublishingPage(newPageName, pageLayout));
                    if (publishingPage != null && doCreateFriendlyUrl && publishingPage.ListItem.ParentList.ForceCheckout)
                    {
                        publishingPage.CheckIn(string.Empty);
                        publishingPage.CheckOut();
                    }
                }
                catch (SPException ex)
                {
                    if (doCreateFriendlyUrl && (ex.ErrorCode == -2130575306 || ex.ErrorCode == -2130575257))
                    {
                        tryNakedToken = false;
                        goto end_IL_0082;
                    }
                    throw;
                    end_IL_0082 :;
                }
            }while (doCreateFriendlyUrl && publishingPage == null);
            return(publishingPage);
        }
예제 #7
0
        private static void EnsurePageCheckInAndPublish(PageInfo pageinfo, PublishingPage page)
        {
            string comment = "Dynamite Ensure Creation";

            if (page.ListItem.File.CheckOutType != SPFile.SPCheckOutType.None)
            {
                // Only check in if already checked out
                page.CheckIn(comment);
            }

            // Are we publishing this page or not ?
            if (pageinfo.IsPublished)
            {
                if (page.ListItem.ParentList.EnableModeration)
                {
                    if (page.ListItem.ModerationInformation.Status == SPModerationStatusType.Draft)
                    {
                        // Create a major version (just like "submit for approval")
                        page.ListItem.File.Publish(comment);

                        // Status should now be Pending. Approve to make the major version visible to the public.
                        page.ListItem.File.Approve(comment);
                    }
                    else if (page.ListItem.ModerationInformation.Status == SPModerationStatusType.Pending)
                    {
                        // Technically, major version already exists, we just need to approve in order for the major version to be published
                        page.ListItem.File.Approve(comment);
                    }
                }
                else if (page.ListItem.File.MinorVersion != 0)
                {
                    // Create a major version, No approval required for this case.
                    page.ListItem.File.Publish(comment);
                }
            }
        }
예제 #8
0
        private static void EnsurePageCheckInAndPublish(PageInfo pageinfo, PublishingPage page)
        {
            string comment = "Dynamite Ensure Creation";

            if (page.ListItem.File.CheckOutType != SPFile.SPCheckOutType.None)
            {
                // Only check in if already checked out
                page.CheckIn(comment);
            }

            // Are we publishing this page or not ?
            if (pageinfo.IsPublished)
            {
                if (page.ListItem.ParentList.EnableModeration)
                {
                    if (page.ListItem.ModerationInformation.Status == SPModerationStatusType.Draft)
                    {
                        // Create a major version (just like "submit for approval")
                        page.ListItem.File.Publish(comment);

                        // Status should now be Pending. Approve to make the major version visible to the public.
                        page.ListItem.File.Approve(comment);
                    }
                    else if (page.ListItem.ModerationInformation.Status == SPModerationStatusType.Pending)
                    {
                        // Technically, major version already exists, we just need to approve in order for the major version to be published
                        page.ListItem.File.Approve(comment);
                    }
                }
                else if (page.ListItem.File.MinorVersion != 0)
                {
                    // Create a major version, No approval required for this case.
                    page.ListItem.File.Publish(comment);
                }
            }
        }
        private static void EnsurePageCheckInAndPublish(PublishingPage page)
        {
            if (page.ListItem.File.CheckOutType != SPFile.SPCheckOutType.None)
            {
                // Only check in if already checked out
                page.CheckIn(string.Empty);
            }

            if (page.ListItem.ModerationInformation.Status == SPModerationStatusType.Draft)
            {
                // Create a major version (just like "submit for approval")
                page.ListItem.File.Publish(string.Empty);

                // Status should now be Pending. Approve to make the major version visible to the public.
                page.ListItem.File.Approve(string.Empty);
            }
            else if (page.ListItem.ModerationInformation.Status == SPModerationStatusType.Pending)
            {
                // Technically, major version already exists, we just need to approve in order for the major version to be published
                page.ListItem.File.Approve(string.Empty);
            }
        }