I don't know if you still need the answer, but I had the same question when I stumbled across this post. In my case, I'm consulting for a company that needs to convert over 20,000 static HTML documents into DNN. So, we decided to create new pages with HTML modules dynamically and populate the HTML modules with the existing document content. We used a template web page with an existing HTML module which we copied for the new pages. Here is some sample code I used for a demo.
'Declare DNN page variables
Dim tabInfoParent As New DotNetNuke.Entities.Tabs.TabInfo
Dim tabInfoNew As New DotNetNuke.Entities.Tabs.TabInfo
Dim tabInfo As New DotNetNuke.Entities.Tabs.TabInfo
Dim tabCtrl As New DotNetNuke.Entities.Tabs.TabController
'Get current page
tabInfo = tabCtrl.GetTab(TabId, PortalId, True)
'Get parent page
tabInfoParent = tabCtrl.GetTab(tabInfo.ParentId, PortalId, True)
'Set page information in new page
'PORTAL ID
tabInfoNew.PortalID = Me.PortalId
'PAGE TITLE AND TAB NAME
tabInfoNew.Title = "New HTML Module Test Page"
tabInfoNew.TabName = "New HTML Module Test Page"
'MORE PROPERTIES
tabInfoNew.IsDeleted = False
tabInfoNew.IsSuperTab = False
tabInfoNew.IsVisible = True
tabInfoNew.DisableLink = True
tabInfoNew.IconFile = ""
tabInfoNew.Url = ""
'PARENT PAGE, PERMISSIONS
tabInfoNew.ParentId = tabInfoParent.TabID
tabInfoNew.TabPermissions = tabInfoParent.TabPermissions
'Create the new page, grab the new TabID
Dim intNewTabID As Integer
intNewTabID = tabCtrl.AddTab(tabInfoNew)
'Define module objects and controller object
Dim modCtrl As New DotNetNuke.Entities.Modules.ModuleController
Dim modInfoTemplate As New DotNetNuke.Entities.Modules.ModuleInfo
Dim modInfoNew As New DotNetNuke.Entities.Modules.ModuleInfo
'Get HTML module from template page (use your own module ID of any HTML module)
modInfoTemplate = modCtrl.GetModule(370, Me.TabId, True)
'Clone the module, clear the module ID, add the new page TabID
modInfoNew = modInfoTemplate.Clone()
modInfoNew.ModuleID = Null.NullInteger
modInfoNew.TabID = intNewTabID
'Add the new cloned module to the page, get the new module ID
Dim intModID As Integer
intModID = modCtrl.AddModule(modInfoNew)
' create HTMLText object
Dim objHTML As New DotNetNuke.Modules.HTML.HtmlTextController
Dim objText As DotNetNuke.Modules.HTML.HtmlTextInfo = New DotNetNuke.Modules.HTML.HtmlTextInfo
' set content values (new module ID, encoded HTML, etc.)
objText.ModuleId = intModID
objText.DeskTopHTML = Server.HtmlEncode("<h1>Hello World!</h1><p>Successful new module.</p>")
'objText.DesktopSummary = txtDesktopSummary.Text
objText.CreatedByUser = Me.UserId
' save the content
objHTML.AddHtmlText(objText)
'This is important - you need to make sure the cache is flush or the tab wont appear
DotNetNuke.Common.Utilities.DataCache.ClearModuleCache(intNewTabID)
' redirect to new page
Dim strNewPageURL As String = Me.Request.Url.LocalPath & "?TabID=" & intNewTabID.ToString
Response.Redirect(strNewPageURL, True)
I hope this is helpful to someone in the future. By the way, to know what DNN does with HTML, you can always take a look at the module source code in the /DesktopModules/HTML/ folder. In this case, the EditHTML.ascx.vb file was very helpful.