Pages

Wednesday 27 March 2013

Code-blocks are not allowed in this file: SharePoint 2013

By Default SharePoint did not allowed to inline code . this Trick will work for SharePoint 2013 , SharePoint 2010 and SharePoint 2007.

 To enable this open Web.config for particular site, and search for "PageParser" and Replace the Code with below code .. its simple you have to add Page parser paths , currently i put "/*" as Virtual path , you can use path according to your directory , Such as "/_pages/*"

<PageParserPaths >
<PageParserPath VirtualPath="/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true" />

</PageParserPaths>

After that just create one testing page in SharePoint designer under site pages  and Put following code for testing


<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    string test = "";

    protected void Page_Load(object sender, EventArgs e)
    {
Response.Write("Code Block is Working ");
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta name="WebPartPageExpansion" content="full" />
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    contents
    </div>
    </form>
</body>
</html>


then browse , it will work .

Attach master Page :

Select Style -> Attach -> and select master page that you want to apply.

you script will remove from that page. just copy your script code before apply master page.

After apply master page remove  <form id="form1" runat="server"> </form>  tags.

and paste your script in <asp:Content id="Content1" runat="Server" contentplaceholderid="PlaceHolderMain"> tag.

you final code for testing looks like below image:

Now Browse to see the Result and it will work.









No comments:

Post a Comment