[DNN模块开发]让模块支持“导入”“导出”功能

DNN模块可以支持导入导出功能,通过将模块内容导入到XML文件可以便于模块内容备份和转移,也可将模块内容事先以XML格式保存通过导入功能实现模块内容的批量录入。如图:

要实现模块的导入导出功能,需要在模块的业务逻辑访问对象(***Controller)中实现IPortable接口:
1、IPortable接口 (components\Modules\IPortable.vb)

Namespace DotNetNuke Namespace DotNetNuke.Entities.Modules
' 模块导出导入功能接口
Public Interface IPortable Interface IPortable
' 模块导出
Function ExportModule() Function ExportModule( ByVal ModuleID As Integer ) As String
' 模块导入
Sub ImportModule() Sub ImportModule( ByVal ModuleID As Integer , ByVal Content As String , ByVal Version As String , ByVal UserID As Integer )
End Interface
End Namespace

2、在相应模块的业务逻辑类中实现IPortable接口 (这一步可根据模块具体情况作出相应的修改,可参照DNN已有模块做,如:Links)

Namespace DotNetNuke Namespace DotNetNuke.Modules.Links
Public Class LinkController Class LinkController
Implements Entities.Modules.IPortable

' 实现导出功能接口
Public Function ExportModule() Function ExportModule( ByVal ModuleID As Integer ) As String Implements DotNetNuke.Entities.Modules.IPortable.ExportModule
' 获取该模块的全部链接信息
Dim strXML As String = " "
Dim arrLinks As ArrayList = GetLinks(ModuleID)
' 根据该模块的字段决定XML的节点
If arrLinks.Count <> 0 Then
strXML += "

 1<links>"    
 2![](http://esshs.cnblogs.com/Images/OutliningIndicators/InBlock.gif) Dim  objLink  As  LinkInfo   
 3![](http://esshs.cnblogs.com/Images/OutliningIndicators/InBlock.gif) For  Each  objLink  In  arrLinks   
 4![](http://esshs.cnblogs.com/Images/OutliningIndicators/InBlock.gif) '  编写模块内容的每一条记录    
 5![](http://esshs.cnblogs.com/Images/OutliningIndicators/InBlock.gif) strXML  +=  "  <link/>"    
 6![](http://esshs.cnblogs.com/Images/OutliningIndicators/InBlock.gif) strXML  +=  "  <title> "  &amp; XMLEncode(objLink.Title)  &amp; "  </title>"    
 7![](http://esshs.cnblogs.com/Images/OutliningIndicators/InBlock.gif) strXML  +=  "  <url> "  &amp; XMLEncode(objLink.Url)  &amp; "  </url>"    
 8![](http://esshs.cnblogs.com/Images/OutliningIndicators/InBlock.gif) strXML  +=  "  <vieworder> "  &amp; XMLEncode(objLink.ViewOrder.ToString)  &amp; "  </vieworder>"    
 9![](http://esshs.cnblogs.com/Images/OutliningIndicators/InBlock.gif) strXML  +=  "  <description> "  &amp; XMLEncode(objLink.Description)  &amp; "  </description>"    
10![](http://esshs.cnblogs.com/Images/OutliningIndicators/InBlock.gif) strXML  +=  "  <newwindow> "  &amp; XMLEncode(objLink.NewWindow.ToString)  &amp; "  </newwindow>"    
11![](http://esshs.cnblogs.com/Images/OutliningIndicators/InBlock.gif) strXML  +=  "  "    
12![](http://esshs.cnblogs.com/Images/OutliningIndicators/InBlock.gif) Next    
13![](http://esshs.cnblogs.com/Images/OutliningIndicators/InBlock.gif) strXML  +=  "  </links>

"
End If
Return strXML
End Function

' 实现导入功能接口
Public Sub ImportModule() Sub ImportModule( ByVal ModuleID As Integer , ByVal Content As String , ByVal Version As String , ByVal UserID As Integer ) Implements DotNetNuke.Entities.Modules.IPortable.ImportModule
Dim xmlLink As XmlNode
Dim xmlLinks As XmlNode = GetContent(Content, " links " )
' 从XML中解析每一条记录
For Each xmlLink In xmlLinks.SelectNodes( " link " )
Dim objLink As New LinkInfo
objLink.ModuleId = ModuleID
objLink.Title = xmlLink.Item( " title " ).InnerText
objLink.Url = ImportUrl(ModuleID, xmlLink.Item( " url " ).InnerText)
objLink.ViewOrder = Integer .Parse(xmlLink.Item( " vieworder " ).InnerText)
objLink.Description = xmlLink.Item( " description " ).InnerText
objLink.NewWindow = Boolean .Parse(xmlLink.Item( " newwindow " ).InnerText)
objLink.CreatedByUser = UserId.ToString
AddLink(objLink)
Next
End Sub

End Class
End Namespace

注意: 在打包安装文件时,需要在DNN文件的

1<businesscontrollerclass>节点写明该模块的业务逻辑类,如:   
2
3
4![](http://esshs.cnblogs.com/Images/OutliningIndicators/None.gif) &lt; businesscontrollerclass  &gt; DNNChina.Modules.CLinks.CLinksController, DNNChina.Modules.CLinks  </businesscontrollerclass>

相关内容:
DNN模块的层次划分: http://www.cnblogs.com/esshs/archive/2005/07/27/201190.html
关于模块文件结构: http://www.cnblogs.com/esshs/archive/2005/07/21/197198.html
关于DNN文件结构: http://www.cnblogs.com/esshs/archive/2005/07/26/200154.html

更多相关内容>>

Published At
Categories with Web编程
Tagged with
comments powered by Disqus