Background
In DotNetNuke page's are programmatically known as tabs (this was the legacy term used in the original Ibuyspy code). When operating with pages via code, page instances are stored in the TabInfo class and manipulated via the TabController class, both of which are in the DotNetNuke.Entities.Tabs namespace
Note: The API documentation can be downloaded from the
downloads page.
Creating the page via code
Note: When creating a new page via code, it is not sufficent to create the page itself. DotNetNuke implements a rich set of permissions including page permissions (via the TabPermissionCollection), so new pages require permissions to be programatically set otherwise they cannot be navigated to.
To create a page programmatically code similar to the following is used:
Dim controller As New TabController
Dim newTab As New Tabs.TabInfo
Dim newPermissions As TabPermissionCollection = newTab.TabPermissions
Dim permissionProvider As PermissionProvider = permissionProvider.Instance
Dim infPermission As TabPermissionInfo
' set new page properties
newTab.PortalID = PortalId ' the portal you want the page created on
newTab.TabName = PageName 'the new page name
newTab.Title = PageTitle 'the new page title
newTab.Description = Description 'the new page description
newTab.KeyWords = Keywords 'the new page keywords (used for meta keywords and search)
newTab.IsDeleted = False 'whether it is deleted - always false for new pages
newTab.IsSuperTab = False 'whether it should only be accessible by superusers
newTab.IsVisible = True 'whether it is visible
newTab.DisableLink = False 'whether it has a menu link
newTab.IconFile = "" 'the image file used in the menu
newTab.Url = "" 'if the page is a redirection to a URL such as another page or an external site
newTab.ParentId = <insert relevant pageid here - see notes below>
' create new page
controller.AddTab(newTab, LoadDefaultModules)
' copy permissions selected in Permissions collection
For index As Integer = 0 To (Permissions.Count - 1)
infPermission = New TabPermissionInfo
infPermission.AllowAccess = Permissions(index).AllowAccess
infPermission.RoleID = Permissions(index).RoleID
infPermission.RoleName = Permissions(index).RoleName
infPermission.TabID = Permissions(index).TabID
infPermission.PermissionID = Permissions(index).PermissionID
'save permission info
newPermissions.Add(infPermission, True)
permissionProvider.SaveTabPermissions(newTab)
Next index
Notes:
- if you purely want a clone of a tab then the
TabController
already has the handy, if not very flexible, TabController.CopyTab
method.
Useful references