How to Create a Wiki Page template For SharePoint 2010 Foundation


Introduction
As I have ever written several time in my previous posts, one of the severe limitation of SharePoint Foundation is that the Wiki Pages are based on a single template wkpstd.aspx located at
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\DocumentTemplates
If you try to add a wiki page programmatically to a wiki page library of a SharePoint Foundation team site and you want it to be ghosted you must use the method SPFileCollection.Add with this signature :
 Add(String, SPTemplateFileType)
And pass the reference of the wiki page template wkpstd.aspx to the SPTemplate parameter. If you use any other signature, you will be able to add a wikipage, but it will be unghosted.
I am now going to show you a very amazing workaround to use another template than the wkpstd.aspx one and will process in  two steps. First I will demonstrate it so as you can easily understand its principle then I will provide a programmatic way of doing it.


Demonstration
Start creating your new template by duplicating the wkpstd.aspx and rename it wkpcustom.aspx, then perform a little operation of customization in order each page based on this new template can tell its name :
In the page directive section add the namespace System.Diagnostics because the wiki pages will tell their nam in the debugView...
<%@ Import Namespace="System.Diagnostics" %>
Then, at the top of the PlaceHolderMain section paste this code:
protected override void OnPreInit(EventArgs e)
{
     base.OnPreInit(e);
    Debug.WriteLine(SPContext.Current.File.Name);
}


Then, we are going to prepare a feature to reference this wkpcustom.aspx file in a SharePoint Foundation wiki page library.

NEXT PAGE: CLICK HERE