Thursday, October 30, 2008

How to generate a template in SharePoint 2007 with solving all problems which will face...

How to generate a template in SharePoint 2007 and fix all problems you will face:

I have a task to create more than 5000 site from a temple, during my work, I faced many problems and I tried to solve them: 1. When we save a site as template, all sub sites don’t included in the template, so we should create a site programmatically and then create sub site inside it also programmatically as following:

private static SPWeb createSite(SPWeb parentWeb, string siteURLRequested, string siteTitle, string siteTemplateName, int Language_ID, bool useUniquePermissions, bool inherentNavigation)

{

if (parentWeb.Webs[siteURLRequested].Exists)

{

parentWeb.Webs.Delete(siteURLRequested);

}

SPWeb newWeb = parentWeb.Webs.Add(siteURLRequested, siteTitle, "", Convert.ToUInt32(Language_ID), siteTemplateName, useUniquePermissions, false);

newWeb.Navigation.UseShared = inherentNavigation;

newWeb.Update();

}

2. When we create a site from a template, we encounter an error that the home page didn’t see its layout: To solve this problem we should create a new default page from empty web part layout. So all default pages in the site and its sub sites should be created from a new layout or empty web part layout.

3. 3. When we have a content query web part in parent site and the web part display data from its sub sites, we will notice in our generated sites this web part don’t display data, because the ListGuid in the web part is wrong .

4. To solve this problem : we should detach the page from page layout then go to the web part and delete the ListGuid Attribute from web part and then our web part will work correctly, also this web part will display the data when we generate the site from template.

4. For the Data Web Part , we should exchange the ListID with ListName in Select Parameter Tag.

After you apply step 2, 3, and 4 , save your site and sub site as template , then generate site from that template and you will notice that your generated site will work correct.