Products

Solutions

Resources

Partners

Community

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Create a new page programmatically

Return to previous page

  • 4/7/2015
  • 8629 Views

Comments

8629 Views

Create a new page programmatically

Last updated long time ago

Comments

Common

(Enter the content of this article below)

Advanced

 

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:
  • Pages require a "parent" page id. Whilst this might be fixed (e.g. create all new pages under a particular page), sometimes code will look to add it under the current page. A popular option for this would be to pull back the tabid for the current module e.g.
    objModuleInfo = objModuleContr.GetModuleByDefinition(PortalId, "UserReg")
    
    intModTabID = objModuleInfo.TabID
    newTab.ParentId = intModTabID


  • it's of course possible to "clone" a tab, but retrieving it's definition from an existing tab and then saving it elsewhere e.g.
    dim newTab as TabInfo = controller.GetTab(oldTabId, portalID, true)
    . However, if doing this on versions 5.5.0 or higher, please ensure that you change the uniqueID value i.e newTab.UniqueId = System.Guid.NewGuid()

  • 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

Contents
No sections defined
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out