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 Exc开发者_运维知识库eption
'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.
Version 5.2 of the HTML module (which started being distributed with DNN 5.2) and above are compiled, with a reference in the website's /bin/ directory. You can make a reference to DotNetNuke.Modules.Html.dll in your project and use the methods on HtmlTextController
to make the updates (as @mika mentions). However, because of changes to the HTML module over time, you'll need to make sure that you re-check your module (and potentially update your integration) every time you update DNN.
You can take a look at our free Engage: F3 module to see how we've addressed differences in the code bases of various versions.
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)
精彩评论