Search code examples
apidotnetnukedotnetnuke-module

How to update DotNetNuke's HTML module content through code?


I'm working on a DNN module which needs to be able to update the HTML content of existing HTML modules. Does anyone know how to do this through code?

I've determined the content gets stored in the HtmlText table, but I'd rather not write directly to the table. Does anyone knows how to accomplish this using the DNN API?

Thanks in advance.


Here's the solution I found, with the help of mika & bdukes :

''' <summary>Add HTML contest to an existing HTML module.</summary>
Private Sub AddHTML(ByVal ModuleID As Integer, ByVal HTML As String)
    Try
        Dim oHTML As New DotNetNuke.Modules.Html.SqlDataProvider
        '-- i'm not sure what "history" should be set for in the method below.
        '-- i suspect it means "version history", which 5 seems to be the default based on what i've read.
        oHTML.AddHtmlText(ModuleID, HTML, 1, 1, UserId, 5)

    Catch ex As Exception
        'failure
    End Try
End Sub

Notes:

  • This routine adds HTML content to a just-created HTML/Text module, so checking for existing HTML content isn't necessary.

  • I'm a little fuzzy about the 3rd and 6th parameters (StateID & History), although it seems to be working correctly. If anyone knows more about them, I'd like to know the correct way to set these parameters.


Solution

  • Use Text/HTML module. It is not distributed as a .dll, but you'll find the code in the /App_Code/HTML folder.

    HtmlTextController has the methods:

    - Public Sub AddHtmlText(ByVal objText As HtmlTextInfo) 
    - Public Function GetHtmlText(ByVal moduleId As Integer) As HtmlTextInfo 
    - Public Sub UpdateHtmlText(ByVal objText As HtmlTextInfo)