Resolving the “Accessing referenced file from is not allowed” issue in Sharepoint

Very often, Sharepoint publishing pages display the following message after modifying the master page or the page layouts using Visual Studio:

“Accessing referenced file from is not allowed”

If you browse to the mapped folder of the publishing site, you will find that some temporary strange files are created and generally, the files have the extension “tmp”. Deleting the files is no help because they are either locked, either re-created again by SharePoint. A simple F5 refresh will make these files reappear.

The trickiest thing is that the publishing pages using the locked page layout are neither accessible by the end user, neither by the search service. Hence, all the content search web parts searching for content using the page layout display no result !

The most obvious workaround is to create a clone page layout that does not reference the unwanted file and to associate the new page layout to the page. However, the page is inaccessible by the portal, so to do this, we have to perform the following steps:

A- Create a clone page layout

1- Go to the mapped folder and locate the locked page layout

2- Perform “copy & paste” on the problematic page layout

3- Rename the new file using a human-identifiable name, let’s say “LAYOUT 2”

4- Go to the site settings

5- Locate the new page layout in the master page and page layouts gallery

6- Modify the properties of the new page layout. Ensure that the type is “Page Layout” and not “Creation File” or something else.

7- Publish the new page layout

B- Assign the page layout using Powershell

Now, let’s find the new page layout and assign it to my locked page using PowerShell.

1- Create an instance of a publishing site pointing to my portal

$site = new-object Microsoft.SharePoint.Publishing.PublishingSite($url)

Where $url is the address of my portal.

2- Now, let’s obtain my new page layout :

$layout = $site.GetPageLayouts($true) | Where-Object {$_.Name -eq "NEWLAYOUTNAME.aspx”"}

3- To be sure that the variable “$layout” is not empty, type “$layout” in the console to view the content. If it is empty, be sure that you have typed the adequate layout name

Let’s get a reference to the root website of the site collection :

4- $web = $site.RootWeb

After, we have to obtain an instance of a publication website for the possibility of browsing the site pages :

5- $pubWeb = $pubweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web);

Let’s find the page by title :

6- $page = $pubweb.GetPublishingPages() | Where-Object {$_.Title –eq “MYPAGETITLE”}

7- Type $page to display the content of the variable to be sure that the query did not return an empty result.

8- Now, that we have the page layout and the page, we can modify the page using this small script :


$page.Layout = $layout


$page. CheckIn(« Updated page layout using Powershell »)

9- Check that your page is now accessible and waiting to be published.

Hope that these scripts helped to overcome a very annoying issue with SP/VS.

Enjoy !

References :

· PublishingSite class (Office Dev Center),

· PublishingWeb class (Office Dev Center),

· Powershell script for updating a publishing page Page Layout in a site collection, Chris "Jake" Jacobsen Blog,

Add comment