Showing posts with label publishing page. Show all posts
Showing posts with label publishing page. Show all posts

Friday, 6 January 2017

Create Publishing Page using Custom PageLayout by PowerShell in SharePoint 2013

Hi - Today i will share the code for creating Publishing Page based on a custom Pagelayout using powershell


$siteUrl="ur site URL here"

$site = Get-spsite $siteUrl
$web = $site.OpenWeb()
$pubWeb =[Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
#Name of the page layout. It can also be your custom template
$pl = $pubWeb.GetAvailablePageLayouts() | Where { $_.Name -eq "BlankWebPartPage.aspx" }
$newPage = $pubWeb.AddPublishingPage("newpage.aspx", $pl)
$newPage.CheckIn("")
$newPage.ListItem.File.Publish("")
$web.Dispose()

Happy coding..

Friday, 4 November 2016

SharePoint - Programmatically get Friendly URL of Publishing pages

Hi Guys - After so long time, I am posting this. I got so busy in my project. Finally I am getting some time to post this. I got his requirement of finding the Friendly URL of Publishing pages.

Code is given below. Hope this helps someone.



using (SPSite osite = new SPSite("site url"))
            {
                using (SPWeb oweb = osite.OpenWeb())
                {
                    SPList olist = oweb.Lists["Pages"];
                    foreach (SPListItem item in olist.Items)
                    {
                        var associatedTerms = TaxonomyNavigation.GetFriendlyUrlsForListItem(item, false);

                        string url = string.Empty;
                        if (associatedTerms.Count > 0)
                        {
                            url = associatedTerms[0].GetResolvedDisplayUrl(string.Empty);
                        }
                    }
                }
            }


Happy Coding :)