This snippet of code shows you how to programmatically create a page (tab) in DotNetNuke 4.x from a template.
It is called from the context of a module, so we have access to some of the main objects of DNN framework, such as PortalSettings.
Few properties are copied from the current active page: TabPermissions, SkinSrc, ContainerSrc. With a little effort you can specify your own values, if these ones are not appropriate.
The most important point is the use of the page template. By default, DotNetNuke comes with one template that is adding a HTML module to the main ContentPane. This template is placed in “…\Portals\_default\Templates\ Default.page.template” file. It is a XML file and you can easily change it or clone it to create your own template.
'create new hidden page
Dim ctrTab As New DotNetNuke.Entities.Tabs.TabController
Dim objTab As New DotNetNuke.Entities.Tabs.TabInfo
Dim objActiveTab As DotNetNuke.Entities.Tabs.TabInfo
objActiveTab = Me.PortalSettings.ActiveTab
objTab.IsVisible = False
objTab.PortalID = Me.PortalId
objTab.TabID = Null.NullInteger
objTab.PortalID = PortalId
objTab.TabName = "Page Name"
objTab.Title = "Page Name"
objTab.Description = "Description"
objTab.KeyWords = ""
'we make it hidden this time
objTab.IsVisible = False
objTab.DisableLink = False
objTab.ParentId = -1
objTab.IconFile = ""
objTab.IsDeleted = False
objTab.Url = "N"
'get the same permissions as the current active page
objTab.TabPermissions = objActiveTab.TabPermissions
'get the same skin as the current active page
objTab.SkinSrc = objActiveTab.SkinSrc
objTab.ContainerSrc = objActiveTab.ContainerSrc
objTab.TabPath = GenerateTabPath(objTab.ParentId, objTab.TabName)
objTab.StartDate = Null.NullDate
objTab.EndDate = Null.NullDate
objTab.PageHeadText = ""
objTab.TabID = ctrTab.AddTab(objTab)
'create the page from our template
Dim xmlDoc As New System.Xml.XmlDocument
xmlDoc.Load(Server.MapPath(Me.Page.TemplateSourceDirectory & "/Portals/_default/Templates") & _
"\Default.page.template")
I will conclude that creating pages programmatically is not complicated in DotNetNuke, and can be useful in the process of custom module creation, when we want to save the admin user few extra steps.