Thursday, 19 July 2018

Change the layout page of a publishing page

Issue

Update an exiting page to a new layout page and need to update all my sites page to the new layout page.


Code
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Site that I would like to implement the change on
$StartWeb="https://intranet.peelschools.org/ltss/pmo/PMLC"

#filter to only the sites that I want
$subsites = ((Get-SPWeb $StartWeb).Site).allwebs | ?{$_.url -like "$StartWeb*"}
$pWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($subsites)
$pSite = New-Object Microsoft.SharePoint.Publishing.PublishingSite($subsites.Site)

#need the root of the site collection to get the layout page from
$rootSite = Get-SPSite https://intranet.peelschools.org
$site =$subsites
$lookForList = "Pages"

   foreach($subsite in $subsites){

            $spPubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($subsite)
            $pages = $spPubWeb.PagesList
            $myLayout = $siteLayouts["/_catalogs/masterpage/PDSB/Content.aspx"]

            #Add site content types to the list
            $ctToAdd = $rootSite.RootWeb.ContentTypes["Intranet SP2013"]
            $ct =  $pages.ContentTypes.Add($ctToAdd)
            write-host "Content type" $ct.Name "added to list"  $pages.Title
         

            foreach($item in $pages.Items)
            {
                $pubPage = [Microsoft.SharePoint.Publishing.PublishingPage]::GetPublishingPage($item)
               
                if ($pubPage.Title -ne "Forms" -and $pubPage.Title -ne "All Documents" -and $pubPage.Title -ne "Documents")
                {           
                    $pubPage.CheckOut()
                    $pubPage.Layout = $myLayout
                   # $pubPage.item["Show Resources in page"]=$true
                   $pubPage.
                    $pubPage.Update()
                    $pubPage.CheckIn("")
                    $pageFile = $pubPage.ListItem.File
                    $pageFile.Publish("")
                 }                     
            }
            Write-Host $subsite.url  "is done"
 }

$subsites.Dispose()
$rootsite.Dispose()

$site.Dispose()

Display attachments as an image

Request

Display the attachments as image using jquery script.  The attachments are images that have been uploaded.  The attachments are still links but the image is displayed on the form in read mode.

Example


Code 
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js">​
</script>
<script type="text/javascript">
    $(document).ready(function(){
$('#idAttachmentsTable tr td span a').each(function() {
$(this).text('');
var a_href = $(this).attr('href');
$(this).append("<img alt='' src='" + a_href + "' width=80% />");


});

    });
    </script>

Results