蓝桥之魂

Created by ZHU, Henry Cijun

导航

How to create published content types, page layouts and pages (SharePoint 2010)

 

1.       Create published content type

(a)     Create a SharePoint 2010 project in VS 2010.

(b)     Create a new sitecollection feature with an empty “elements.xml”.


 

(c)     Strike the code in “Elements.xml”

<?xml version="1.0" encoding="utf-8"?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

 <Field ID="{E19F4F1A-F1EF-4665-B4FB-350264623789}" Type="HTML" DisplayName="Article Content" Name="ArticleContent" Group="My Column"></Field>

 <Field ID="{FDAD7025-FBDD-472a-BC71-2CFD16E2B40D}" Type="Text" DisplayName="Article Title" Name="ArticleTitle" Group="My Column"></Field>

 <Field ID="{CC54BCB8-6EAD-4f75-9983-0ABEBBAB6D67}" Type="Note" DisplayName="Article Abstraction" Name="ArticleAbstraction" Group="My Column"></Field>

 

 <ContentType ID="0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39001171BA2D0ACC4a649A9D86EFBBA5573E" Name="My Article Content Type" Overwrite="TRUE" Group="Page Layout Content Types" Description="Page layout developed by Henry ZHU." Version="0">

    <FieldRefs>

      <FieldRef ID="{FDAD7025-FBDD-472a-BC71-2CFD16E2B40D}" DisplayName="Article Title" Name="ArticleTitle"/>

      <FieldRef ID="{E19F4F1A-F1EF-4665-B4FB-350264623789}" DisplayName="Article Content" Name="ArticleContent"/>

      <FieldRef ID="{CC54BCB8-6EAD-4f75-9983-0ABEBBAB6D67}" DisplayName="Article Abstraction" Name="ArticleAbstraction"/>

    </FieldRefs>

 </ContentType>

</Elements>

We have created a content type based on content type – “Page”, which is the proper base content type for published content types.

In SharePoint 2007/2010, inheritance among content types reflects to ID property. For example, the ID we used for our new content type is 0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39001171BA2D0ACC4a649A9D86EFBBA5573E.

The child content type will use its parent’s ID plus “00” followed its own GUID (grey part).

We can get ID of “Page” in Content Type page. Copy the value of “ctype” from URL column.

http://mysitecollection/sites/pub/_layouts/ManageContentType.aspx?ctype=0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39&Source=......

(d)     Deploy the solution and activate the feature

(e)     Verify your work


 


 

2.       Create a master page for your publishing site

(a)     Create another SharePoint 2010 project

(b)     Add a “Module” in “New Item” menu

“Module” is a tag tells SharePoint we want to copy some files to a SharePoint library.

(c)     Get a copy of “minimal.master” from SharePoint designer or master page library. This master page contains all controls and resources which are necessary and vital for SharePoint. We will make modification based on this version.


 

(d)     Rename “minimal.master” and add it into our project


 

(e)     Modify this master page. Use “SPSecurityTrimmedControl” to hide some areas from users can only read.

<SharePoint:SPSecurityTrimmedControl runat="server" PermissionsString="ManageWeb">

This control will show or hide the embraced content according to the permission of the current login user. In our case, we want to show “Site Action” button to site owner only while end user can only view the content area.

(f)      Edit “Elements.xml”

<?xml version="1.0" encoding="utf-8"?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

 <Module Name="MasterPage" Url="_catalogs/masterpage">

    <File Path="MasterPage\MyMasterPage.master" Url="MyMasterPage.master" IgnoreIfAlreadyExists="FALSE" Type="GhostableInLibrary" />  

 </Module>

</Elements>

This will copy the master page to the master page library.

(g)     Deploy the solution and activate the feature.

(h)     Set our newly created master page as the “Custom Master Page” in SharePoint designer by right-click the master page file. You can also choose to create an event handler on a feature to achieve this. It’s up to you.

We have two different kinds of “Default” master page in SharePoint. The first is called “Default Master Page” which is used for non-publishing pages such as web part page or list page. On the other hand, we have another which is called “Custom Master Page”.

 

(i)       Verify your work – Try to login with two accounts, one for site owner and the other for a read only user.


 


 

3.       Create page layouts based on content type

(a)     Create an aspx file in MasterPage folder

Aspx page should inherit “Microsoft.SharePoint.Publishing.PublishingLayoutPage”

 


 

(b)     Modify “elements.xml”

<?xml version="1.0" encoding="utf-8"?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

 <Module Name="MasterPage" Url="_catalogs/masterpage">

    <File Path="MasterPage\MyMasterPage.master" Url="MyMasterPage.master" IgnoreIfAlreadyExists="TRUE" Type="GhostableInLibrary" />

    <File Path="MasterPage\PageLayout_MyArticle.aspx" Url="PageLayout_MyArticle.aspx" Type="GhostableInLibrary">

      <Property Name="Title" Value="My Article Page Layout" />

      <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />

      <!--Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/CustomPageLayout.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/CustomPageLayout.png" /-->

      <Property Name="PublishingAssociatedContentType" Value=";#My Article Content Type;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39001171BA2D0ACC4a649A9D86EFBBA5573E;#"/> <!- The content type we created before -->

    </File>

 

 </Module>

</Elements>

 

(c)     Deploy the project.

4.       Create a publishing page with page layout

(a)     Create a publishing page with the page layout we imported

 


 

(b)     Edit the property of publishing page


 

(c)     Final resultf

 

 Source Code: /Files/deltag1984/Henry.SP2010.PublishSite.rar

 

posted on 2012-06-01 04:18  Henry Zhu  阅读(667)  评论(0编辑  收藏  举报