Pages

Sunday, June 14, 2009

How site Templates can be moved to Central Site Template Gallery

Hello Friends,

Business Case:

 In our organizations there are more than one Intranet Portals. Different web application like one is parent and web application for each department – its sub department, each for user required solutions (we called as application). Now main requirement is every portal has look wise same. Like every intranet portal must have some of lists like “Department, Divisions, Menus, etc. “. Some of intranet portal does not have Quick Launch and while some have. Welcome page must be same. Site themes some of font styles, home logo, banners must be same.

Problem:

Problem is for every application we have to manually create lists and makes entry as well as we have to change quick launch and also some other layouts modification we have to do manually from SharePoint Designer. Really a very tedious work for developers.

Existing Scenario:

Created web application from central Admin by selecting one of template from out of box and did manually changes. Same thing do again and again!! Wastage of time.

Possible Scenario:

So we decided that we have to create our own site Template and apply that site template to newly created web application depends on requirement whether we require new application with quick launch or not.

 Possible Solutions:

We have two options to create custom template 1) Site Definition 2) Site Template

Let me explain you when we have to use SiteTemplate & SiteDefinition and

When we discuss this topic how can we forget about Ghosting & UnGhosting and main topic is when we use siteTemplate how we can add that thing to CentralAdmin.

What is Ghosting-Unghosting & Difference between Ghosting & Unghosting:

When you create a new site, SharePoint doesn't have same pages for different sites— default.aspx and so on—into a new database table or directory. These files exist once and only once on each of the front end Web servers. Instead, SharePoint creates a reference to those files in the database tables that define the new site, a process called "ghosting." The outcome is that the site appears to have its own unique pages, but the pages are actually shared across all sites that use the same definition. So ghosting is jargon which is used in SharePoint 2003 and same concept but in SharePoint 2007 it is known by new word and that is “Uncustomized”.

This has two distinct advantages over copying the files to each site individually when the site is created. It saves space. Say example, If you have a hundreds sites, rather than having a hundreds copies of same file you still have only one copy. It improves performance. The server needs to cache only one copy from the file system, which can improve performance by freeing cache memory for other things. Loads the file from the Web server's local file system improves performance by eliminating the overhead of the database call and the network traffic to the database. One interesting benefit of this approach is that when you make a change to one file on the file system, that change takes effect across all the sites that have been created. There are some limitations like SharePoint can not ghost every page so we use concept Unghosting. Unghosting means when we customize page whose customization stored in database it is known as “unghosting” in SharePoint 2003 and “customized” in SharePoint 2007. Unghosting lets users customize their own sites without impacting other users who might be using the same file. But unghosting also has a performance impact negatively. Normally there are some of Site templates are already available which are out of box to Site Templates Like “Team Site”, “Blank Site”, Meeting workspace” There is very common and frequently requirement for customizing portal sites and other SharePoint sites. There are normally two approaches uses for customizing sites they are: 1> Site Definition 2> Site Templates Let I will give you description of every approach and also let you know when we have to use both.

 When to use Site Definition:

 A site definition defines a unique type of SharePoint site.When we use site definitions we require access to the file systems of the Web server. When we use site definition we will edit the Schema files directly. In spite of deploying a site definition requires more tedious and manually work, site definitions typically perform better when cached on the file system instead of in the database. We have finer level of customization by directly editing all the schema files and not depending on the existing site definition as a site template does. To introduce new file types, view styles, and drop-down edit menus, just need to edit the schema files that make up the site definition. Custom Site Definition also has capability of versioning. Using custom site definitions excludes your sites from potential upgrade issues. However, there is no easy way to modify site definitions once they are deployed. You can only add new types, view types to the site definition once it is deployed. 

 When to Use Site Templates Site templates, compared to site definitions, are easy to create and deploy. Because customization can be done through SharePoint Designer 2007 or user interface. Modification is really easy as compared to Site Definition and it does not effect to existing sites created by that templates. Deployment is simple because template data is stored centrally in the configuration database. Because it is slow to store templates in and retrieve them from the database, site templates can result in slower performance. Templates in the database are compiled and executed every time a page is rendered. Windows SharePoint Services does some performance optimization whereby it stores templates on the local Web server and a copy (or “ghost”) of the page in the configuration database. Rendering pages from the database will result in an initial performance penalty. If the site definition does not exist on the server, the site template fails.

 Solutions Offered Finally:

Typically, because of these issues, site templates are not as efficient as site definitions in a large-scale environment. It is used when we have to go for very small changes to like changes in logo, small things. Site templates are stored in the Site Template Gallery of the top-level site in a site collection, where they become available for subsite creation on all sites in the site collection.

How site Templates can be moved to Central Site Template Gallery?

Here it is: When we create some Site templates we can use it any site and now if you want to display that site template in Central Admin and apply it to entire web application and globally Available …we have to use stsadm command line tool and use addtemplate command. In my project we want one siteTemplate which does not have Quick Launch and some lists are common like Office, Division and Department. So first we think that we have to create site definition because we want that thing as globally available to Central Admin. But we are unaware of functionality of stsadm addtemplate command. Then once we know about that first I updated default.master from SharePoint Designer. In that site I added 3 lists Office, Division and Department. Then from siteSettings we save that template as Site Template to Local drive.

Then use command

stsadm –o addtemplate -filename “C:\CustomTemplate.stp” –title “A Template without Quick Launch” Description of the command is as follows:

 Command Syntax like: stsadm -o addtemplate -filename -title

 

Parameters


























ParameterValueRequired?Description
FilenameA valid file name, such as “C:\Templates\SampleTemplate.stp”YesFile name of the template that you are adding
TitleA valid title of a template, such as “Sample Template”YesTitle of the template that you are adding
descriptionA valid description of the template, such as “This is a sample template”NoDescription of the template that you are adding

 

Stsdm –o addtemplate –filename  “Path of file siteTemplatefile” –title  “Title of SiteTemplate when it displays at SiteTemplate Tag”

Don’t forget to do iisreset and now it is available to central admin as global template.

  • Second way to do this thing is:


In code, use AddCustomGlobalWebTemplate method of the SPGlobalAdmin class to add a site template to the gallery.

No comments:

Post a Comment