Monday, February 6, 2017

Create aspx or html page and deploy into SharePoint SitePage library without master page inheritance

Hi,  Today I am here with creating a blank .aspx/html page and deploying it into the SitePages library.

Use case: Some of pages like details submit page may or may not needed quick launch, logo and other Title bread crumb info.

Create aspx or html page and deploy into SharePoint 'SitePage' library without master page inheritance 

Out put of the Project:


Step 1: Create SharePoint Solution,
Step 2: Right click on project, select add new item and select module (SharePoint):  Name it: Employee
Step 3 (ASPX): Solution Explorer under Employee module, sample.text to mypageX.aspx
Step 4 (Code Behind): Right click on module and add new Item from code section select a class template and name it as: mypageX.aspx.cs


                               Note: Step 3 and Step 4 names should be same page

============Copy below code and past in mypageX.aspx page=================
  <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Page Language="C#" CodeBehind="mypageX.aspx.cs" Inherits="TestPage.PagesLocal.mypageX, $SharePoint.Project.AssemblyFullName$" MainContentID="PlaceHolderMain" meta:webpartpageexpansion="full" meta:progid="SharePoint.WebPartPage.Document" %>

<%-- <%@ Page Language="C#" CodeBehind="PageName.aspx.cs" Inherits="ProjectName.ModuleName.PageName, $SharePoint.Project.AssemblyFullName$" MasterPageFile="~masterurl/default.master"      MainContentID="PlaceHolderMain" meta:webpartpageexpansion="full" meta:progid="SharePoint.WebPartPage.Document" %> --%>

<%@ Import Namespace="Microsoft.SharePoint.WebPartPages" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>


<!DOCTYPE html>
<html>
<head>
    <title>Page title</title>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=10" />

    <SharePoint:ScriptLink Name="MicrosoftAjax.js" runat="server" Defer="False" Localizable="false" />
    <SharePoint:ScriptLink Name="SP.core.js" runat="server" Defer="False" Localizable="false" />
    <SharePoint:ScriptLink Name="SP.js" runat="server" Defer="True" Localizable="false" />


    <link rel="stylesheet" type="text/css" href="/_layouts/15/1033/styles/corev15.css" />
    <script type="text/javascript" src="/_layouts/15/init.js"></script>
    <script type="text/javascript" src="/_layouts/15/sp.init.js"></script>
    <SharePoint:ScriptLink Name="sp.ui.dialog.js" runat="server" Defer="True" Localizable="false" />

    <%--<script src="../SiteAssets/CDNs/jquery-3.1.0.min.js"></script>
    <link rel="stylesheet" href="../../../../SiteAssets/CDNs/style.css" /> --%>

    <style type="text/css">
    </style>

</head>

<body>
    <form runat="server">
        <asp:Label runat="server" ID="lblmsg"></asp:Label>

    </form>
</body>

<script type="text/javascript">

</script>
</html>


==================== End of mypageX.aspx  page=====================


Step 2 Get Ready with Code Behind:
Open mypageX.aspx.cs  and make class as a Public and inherit if you want.
I am inheriting from WebPartPages for my Project extension

using Microsoft.SharePoint.WebPartPages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.WebControls;

namespace TestPage.PagesLocal
{
    public class mypageX : WebPartPage
    {
        protected Label lblmsg;
        private void Page_Load()
        {
            lblmsg.Text = "Welcome to Ravimaloth's blogspot...!";
        }
    }
}


================ Module Element.xml =============

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="PagesLocal" Url="Sitepages">
    <File Path="PagesLocal\mypageX.aspx" Url="mypageX.aspx" IgnoreIfAlreadyExists="False" ReplaceContent="TRUE" Type="GhostableInLibrary" />
  </Module>
</Elements>

================ End Module Element.xml =============



 Save and Deploy solution..


Go to SitePages and click on mypageX.aspx ....








No comments:

Post a Comment