Mostefai Mohammed Amine

Software and Cloud Architect

Amine
  • Contact
Previous Post
Next Post
Sep 05, 2015 PowershellSharepointSharepoint 2013

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.CheckOut()

$page.Layout = $layout

$page.ListItem.Update()

$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), https://msdn.microsoft.com/en-us/library/office/Microsoft.SharePoint.Publishing.PublishingSite.aspx

· PublishingWeb class (Office Dev Center), https://msdn.microsoft.com/EN-US/library/microsoft.sharepoint.publishing.publishingweb.aspx

· Powershell script for updating a publishing page Page Layout in a site collection, Chris "Jake" Jacobsen Blog, http://jakejacobsen.net/2011/04/06/powershell-script-for-updating-page-layouts-in-a-site-collection/

Sharepointsharepoint 2013Publishing Sitepowershell
Share This Post

Related posts

  • 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 pag
  • Angular 2 + ASP.NET Core + SASS Starter Visual Studio 2015 Solution Hi, Angular 2 is a very promising framework and one of its biggest advantages is that it takes the p
  • Tutoriel 5.1 - Création d’un service de recrutement–Partie 2 Dans la partie précédente, nous avons créé les services et les workflows nécessaires à notre opérati...
Saving the comment

Cancel reply to comment

The captcha value you provided is incorrect.