Anyway to get started create a SharePoint Project, I'm going to call mine spm.SitePageExample
next I'm going to specify my project to be deployed as a farm solution
Now the first thing I'm going to do before I forget is add a reference to The "Microsoft.SharePoint.Publishing "Extension and the "System.Web" Framework, to do this first right click on references in your solution explorer and click add reference...
With the reference Manager open, make sure under assemblies on the left you have Extensions selected, then check off "Microsoft.SharePoint.Publishing", and "System.Web" and finally click OK.
in your solution explored under References you should see "Microsoft.SharePoint.Publishing" added to the list.
with that out of the way, select your project and hit ctrl+shift+a to add a new item, in the Add New Item window make sure you have sharepoint 2010 items selected on the left and pick the module out of the options.
with that added you should have three files in your module:
- Elements.xml
- Sample.txt
- SharePointProjectItem.spdata
SharePointProjectItem is a hidden file; generally you’ll never have to use it for anything other than troubleshooting. To view the spdata file you have to click show all files icon in your solution explorer.
Open Up the Sample.txt file and paste the following:
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint, Version=14.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities"
Assembly="Microsoft.SharePoint, Version=14.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI"
Assembly="System.Web.Extensions, Version=3.5.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI,
Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" masterpagefile="~masterurl/default.master" CodeBehind="MySitePage.aspx.cs"
Inherits="$SharePoint.Type.df45d565-73d2-447f-a463-5a362d2fc50d.AssemblyQualifiedName$" %>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
<SharePoint:FieldValue id="PageTitle" FieldName="Title" runat="server"/>
</asp:Content>
<asp:Content id="Content1" runat="server" contentplaceholderid="PlaceHolderMain">
<div>Hello World</div>
<div>$SharePoint.Type.df45d565-73d2-447f-a463-5a362d2fc50d.AssemblyQualifiedName$</div>
</asp:Content>
if you would like more information on Sharepoint place holders, check out this. it'll give you a list of SharePoint specific place holders and an explanation of them.
Anyway now that we've pasted this lovely script into our sample.txt page let's go ahead and rename it MySitePage.aspx.
with that complete we now need to create that codebehind page we kept talking about, namely MySitePage.aspx.cs, to do this click on your module in your solution explorer and hit ctrl+shift+a again. This time in the left hand column make sure you have Visual C# items selected then select the Class item, give it the appropriate name (MySitePage.aspx this time) and hit OK.
now your solution explored should fall into place nicely.
there's some more wire up that needs to be completed in your codebehind but this what you should be starting with
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace spm.SitePageExample.CustomSitePage
{
class MySitePage
{
}
}
- using System.Runtime.InteropServices;
- using Microsoft.SharePoint.Publishing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using Microsoft.SharePoint.Publishing;
namespace spm.SitePageExample.CustomSitePage
{
[Guid("df45d565-73d2-447f-a463-5a362d2fc50d")]
class MySitePage
{
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using Microsoft.SharePoint.Publishing;
namespace spm.SitePageExample.CustomSitePage
{
[Guid("df45d565-73d2-447f-a463-5a362d2fc50d")]
public class MySitePage : PublishingLayoutPage
{
}
}
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="CustomSitePage">
<File Path="CustomSitePage\MySitePage.aspx"
Url="CustomSitePage/MySitePage.aspx" />
</Module>
</Elements>
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="CustomSitePage" Url="$Resources:cmscore,List_Pages_UrlName;" Path="CustomSitePage">
<File Path="MySitePage.aspx" Url="MySitePage.aspx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE">
<Property Name="Title" Value="My Site Page" />
<Property Name="ContentType"
Value="$Resources:cmscore,contenttype_pagelayout_name;" />
<Property Name="PublishingPreviewImage"
Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview
Images/DefaultPageLayout.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview
Images/DefaultPageLayout.png" />
<Property Name="PublishingAssociatedContentType"
Value=";#$Resources:cmscore,contenttype_articlepage_name;;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D;#"/>
</File>
</Module>
</Elements>