DNN模块可以支持导入导出功能,通过将模块内容导入到XML文件可以便于模块内容备份和转移,也可将模块内容事先以XML格式保存通过导入功能实现模块内容的批量录入。如图:
要实现模块的导入导出功能,需要在模块的业务逻辑访问对象(***Controller)中实现IPortable接口:
1、IPortable接口(components\Modules\IPortable.vb)
Namespace DotNetNukeNamespace DotNetNuke.Entities.Modules ' 模块导出导入功能接口 Public Interface IPortableInterface 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 InterfaceEnd Namespace2、在相应模块的业务逻辑类中实现IPortable接口(这一步可根据模块具体情况作出相应的修改,可参照DNN已有模块做,如:Links)
Namespace DotNetNukeNamespace DotNetNuke.Modules.Links Public Class LinkControllerClass 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 += "<links>" Dim objLink As LinkInfo For Each objLink In arrLinks ' 编写模块内容的每一条记录 strXML += "<link>" strXML += "<title>" & XMLEncode(objLink.Title) & "</title>" strXML += "<url>" & XMLEncode(objLink.Url) & "</url>" strXML += "<vieworder>" & XMLEncode(objLink.ViewOrder.ToString) & "</vieworder>" strXML += "<description>" & XMLEncode(objLink.Description) & "</description>" strXML += "<newwindow>" & XMLEncode(objLink.NewWindow.ToString) & "</newwindow>" strXML += "</link>" Next 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 ClassEnd Namespace注意:在打包安装文件时,需要在DNN文件的<businesscontrollerclass>节点写明该模块的业务逻辑类,如:
<businesscontrollerclass>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