Showing posts with label Site Content Types. Show all posts
Showing posts with label Site Content Types. Show all posts

Tuesday, February 1, 2011

Planning Content Type Hubs in SP2010

when you are developing enterprise application for large organization some fields are common across all brands such as brand name, brand logo, SEO title, SEO description etc..

How will you handle this common fields across farms?

Scenario (P&G only for reference)

Assume that we are designing architecture for P&G products, normally P&G has lot of products (Pantene, Olay, pampers etc...)but, all these products have some common fields such as Product logo, product name, SEO title, SEO description etc... How will you handle this?

SharePoint 2007

In SharePoint 2007 usually what we do? we go and create separate content type for this called brand content type and deploy this into site collection but, here the problem is we need to go to each and every web application and install site content type feature , there is no central location to place common fields, in future if you want to update particular column, you have to go to each and every web application and update

SharePoint 2010

In SharePoint 2010 there is a new concept called Content Type Hubs, through this you can manage all common fields centrally and publish it to the other web applications, so in 2010 the other web applications can subscribe these content types and pull down the published content types from the CTH and also can get updates when ever changes happened in published content types

Here, mainly you need to concentrate on three things

Site collection to host the content types and act as a Content Type Hubs

Managed metadata service application( to expose content type hub to each and every web application)

Web applications ( to subscribe content type hubs)

Advantages

No need of going to each and every web application and installing the content types and if you want to do updates on particular content type you can simply do it on Content Type Hubs and push it down, so managing the content types easy

In reality the content types changes frequently like adding new fields or creating new content type etc... It's easier to coordinate this from a single location and make sure that xml files are correctly set up across all web applications/farms.

Wednesday, June 16, 2010

Creating site columns thorugh SQL query

Sometimes, you may feel pain while creating site columns and content types through CAML, because you need to know CAML syntax for each and every site column data type, but you can avoid this by simply running one sql query

Normally in SharePoint when we create any site column or content type through SharePoint user interface that will go and stored into content database in the form of CAML, so we can run simple sql query and get that data and build it into features and deploy the same in some other environment means production

Steps

1. create sitecoumns and content types using SP user interface

2. connect to sql server database

3. Execute below query

"Select definition from content types where definition is not null"

4. you can see all site columns and content types in form CAML

5. just extract that and build a features and deploy

Tuesday, September 8, 2009

Creating PageLayouts using Features

Long time back I have posted an article on creating page layouts using SharePoint user interface and designer, now I am going to explain how to create page layouts using features

In this article, I am going to use WSPBuilder for building and deploying SharePoint solution, the main advantage of WSPBuilder is no need of creating manifest.xml , DDf file and cab file, the WSPBuilder will take care of creating all these things, so this will simplify our process

First, I am going to explain what are the entire things do we need for building SharePoint page layouts using features

Please check below image which talks about relation between Site Columns, Content Type and Page layout



Site Columns

A site column is a reusable column definition, or template, that you can assign to multiple lists across multiple SharePoint sites. These columns are directly mapped to table columns in SharePoint database

Her e I have created three columns Activity Name, Activity ID, Activity Image,
While creating site columns please make sure that each column have its own unique ID

You can get Unique ID using GUID tool

VS2008->Tools->Create GUID->Registry Format->Copy

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<Field ID="{d7bc4337-826c-497d-bd46-b7a14afb6a9c}"
Type="Text"
Name="ActivityName"
DisplayName="Activity Name"
StaticName="Activity Name"
Hidden="FALSE"
Required="FALSE"
Group="Activity Columns"
Sealed="FALSE" />
<Field ID="{8BA8E4BC-395F-4a7c-91D7-E9519CC41D11}"
Type="Text"
Name="Activity ID"
DisplayName="Activity ID"
StaticName="Activity ID"
Hidden="FALSE"
Group="Activity Columns"
Required="FALSE"
Sealed="FALSE" />
<Field ID="{EC61E44F-E3FC-430e-BA3A-F457A8945190}"
Type="Image"
Name="Activity Image"
DisplayName="Activity Image"
StaticName="Activity Image"
Hidden="FALSE"
Group="Activity Columns"
Required="FALSE"
Sealed="FALSE" />

</Elements>

Site Content Type


Suppose if you want to manage your organization information in meaning full way across site collection then you can go for Site content types

A content type is a reusable collection of settings you want to apply to a certain category of content. Content types enable you to manage the metadata and behaviors of a document or item type in a centralized, reusable way

Here I have created activity content type that tells to the client that this content type belongs to only activity information

Every content type has FieldRef properties, these properties have a reference to site columns ID’s, that means this field(Site Column)and FieldRef both are pointing to same reference, so whenever we update site column’s that will automatically reflect in content type columns also

See below code all FieldRef Id’s are pointing to sit columns ID’s, if you want you can override some of the properties name, description etc…

Using below code we have created a content type, this is simple content type, it does not do anything so, we have to attach this to base page content type using Content type ID

The content type ID is the combination of base page ID and custom GUID which are separated by 00

Please refer MSDN link for more info on content type id http://msdn.microsoft.com/en-us/library/aa543822.aspx

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ContentType ID="0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900088E14C620BF45afA8B4ADA5F771DB5D"
Name="ActivityContentType"
Group="Demo"
Description="Demo Content Type"
Version="0">
<FieldRefs>
<FieldRef ID="{d7bc4337-826c-497d-bd46-b7a14afb6a9c}" Name="Activity Name" />
<FieldRef ID="{8BA8E4BC-395F-4a7c-91D7-E9519CC41D11}" Name="Activity ID" />
<FieldRef ID="{EC61E44F-E3FC-430e-BA3A-F457A8945190}" Name="Activity Image" />
</FieldRefs>
</ContentType>
</Elements>

Layout page

I suggest you guys create layout page using SharePoint designer and copy into your feature folder, so that you will not face any kind of problems and your work will be smooth

Below page is the which I have created using SharePoint designer

All the SharePoint controls of this layout page have a reference to site columns using Fieldname property, the Fieldname is the name of the site column

<%@ Page language="C#" Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" meta:webpartpageexpansion="full" meta:progid="SharePoint.WebPartPage.Document" %>
<%@ Register Tagprefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ContentPlaceholderID="PlaceHolderPageTitle" runat="server">
<SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server"/>
</asp:Content>
<asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server">

<SharePointWebControls:TextField FieldName="Activity ID" runat="server" id="TextField1">
</SharePointWebControls:TextField>
<SharePointWebControls:TextField FieldName="ActivityName" runat="server" id="TextField2">
</SharePointWebControls:TextField>
<PublishingWebControls:RichImageField FieldName="Activity Image" runat="server" id="RichImageField1">
</PublishingWebControls:RichImageField>

</asp:Content>


ProvisionedFiles.xml

I am using module element for deploying our page in master page gallery

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<Module Name="ActivityPage" Url="_catalogs/masterpage" Path="" RootWebOnly="TRUE">
<File Url="Activity.aspx" Type="GhostableInLibrary">
<Property Name="ContentType" Value="DemoContetType" />
<Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/sample.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/sample.png" />
</File>
</Module >
</Elements>

Feature.xml

<?xml version="1.0" encoding="utf-8"?>
<Feature Id="c2554713-1770-4349-8576-c6f8fe44a950"
Title="PageLayoutDemo"
Description="Description for PageLayoutDemo"
Version="12.0.0.0"
Hidden="FALSE"
Scope="Site"
DefaultResourceFile="core"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>

<ElementManifest Location ="SiteColumns.xml"/>
<ElementManifest Location ="ContentType.xml"/>
<ElementManifest Location ="ProvisionedFiles.xml"/>

</ElementManifests>

</Feature>

So, we have created all necessary files which are required to create pagelayout, now we have to deploy all these files using features

I am using WSPBuilder for deploying all these files, I have posted an article on WSPBuilder please check it, if you need more info



Create a new WSPBuilder Project then create folder structure as shown in fig then copy all the files and build and deploy

For more info on WSPBUilder check my article on WSPBuilder