Skip to main content

SharePoint Error: Code blocks are not allowed in this file

Problem

Users report the following error when attempting to access a document library in SharePoint.

An error occurred during the processing of /site/SharedDocuments/Forms/AllItems.aspx. Code blocks are not allowed in this file.

Explanation

Ever so often I have clients contact me with a SharePoint library fully corrupted reporting an error such as “Code blocks are not allowed in this file”. The error is, in fact, limited to a specific view but it’s usually the default view, therefore the error makes the library appear like it is completely inaccessible. The root cause of the error is simple – a user replaced a view file from the /forms/ folder of the document library, typically “AllItems.aspx” such as the screenshot below suggests. Typically this occurs when the user is using explorer view but I’ve heard of manifest presentations of this error as well.

Solution – Option 1

1) Open site that contains the library

2) Click on “Site Actions” >> “Site Settings” to view the site settings page “_layouts/settings.aspx”

3) Click on the library that displays the error to view the library’s settings page



4) Add a new view to the library and check the box “default view”

Solution – Option 2

In this solution, you are going to replace some of the files in the /forms/ directory of the document library. To do this open 2 document libraries in explorer view and navigate to the “forms” folder which is displayed partially grayed out (note that you may have to show hidden files in your client explorer). In the screenshot below I am replacing the corrupt file “AllItems.aspx” with the same file from another library.

*** If you do NOT know what explorer view is or how to open it then STOP, you should not be doing this.

Comments

Popular posts from this blog

How to get SPUser or SPGroup from Person or Group field

You have person or group field in SharePoint list and you want to programmatically get the user or person. The below code to gets SPUser from User or Group field in the list when multiple choice and Groups are not allowed in the field: //get SPUser SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users"); SPFieldUserValue userFieldValue = (SPFieldUserValue)userField.GetFieldValue(item["Users"].ToString()); SPUser user = userFieldValue.User; This part of code would help you to get SPUser when multiple choice is allowed and groups are not allowed: //Multiple choices are allowed SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users"); SPFieldUserValueCollection userFieldValueCollection = (SPFieldUserValueCollection)userField.GetFieldValue(item["Users"].ToString()); foreach (SPFieldUserValue userFieldValue in userFieldValueCollection) {     Console.WriteLine("     " + userFieldValue.User.LoginName); } And when group...

SharePoint publishing page scheduling

In SharePoint 2010 publishing enabled team site collection is not showing schedule button in publish ribbon. Solution: Here is how to enable it  though the UI: Locate the SharePoint Server Web site on which you want to enable content approval and item scheduling. Click  Site Actions , click  Site Settings , and then click  Modify Pages Library Settings . Under  General Settings , click  Versioning Settings . Click  Yes  next to  Content Approval , and then click  OK . Click  Manage item scheduling .   Click to enable the  Enable scheduling of items in this list  check box, and then click  OK .

Changing Content Type Hub URL

Change the Hub URL through powershell by using: Set-SPMetadataServiceApplication -Identity " " -HubURI " " For Ex: Set-SPMetadataServiceApplication -Identity "Managed Metadata Service" -HubURI "http://contenttype.Domain.Com" When you try to do this you get this rather scary message: This is SharePoint telling you that this is a major thing so be careful! Essentially all your content types that you have published out will be removed if they can, and you have to republish all of your content types out again which can cause some issue.