Allow the module to support "import" and "Export"

Source: Internet
Author: User
Tags dnn dotnetnuke
Allow the module to support "import" and "Export"

The dnn module supports the Import and Export function. By importing the module content to an XML file, you can easily back up and transfer the module content, you can also save the module content in XML format in advance and import the module content in batches.
:

[Img] http://esshs.cnblogs.com/images/cnblogs_com/esshs/20050804.gif#/img]

To implement the module Import and Export function, you need to implement the iportable interface in the module's business logic Access Object (** Controller:

1. iportable interface (Components \ modules \ iportable. VB)
Namespace dotnetnukenamespace dotnetnuke. Entities. Modules
'Module export and import function Interfaces
Public interface iportableinterface iportable
'Module Export
Function exportmodule () function exportmodule (byval moduleid as integer) as string
'Module Import
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. Implement the iportable interface in the business logic class of the corresponding module (this step can be modified according to the specific situation of the module, and can be done by referring to the existing dnn module, such as links)
Namespace dotnetnukenamespace dotnetnuke. modules. Links
Public class linkcontrollerclass linkcontroller
Implements entities. modules. iportable

'Export function interface
Public Function exportmodule () function exportmodule (byval moduleid as integer) as string implements dotnetnuke. Entities. modules. iportable. exportmodule
'Get all the link information of this module
Dim strxml as string = ""
Dim arrlinks as arraylist = getlinks (moduleid)
'Determine the XML Node Based on the field of this module.
If arrlinks. Count <> 0 then
Strxml + = "<links>"
Dim objlink as linkinfo
For each objlink in arrlinks
'Write each record of the module content
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

'Implement the import function interface
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 ")
'Parse each record from 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
Note: When packaging the installation file, you must specify the business logic class of the module in the <businesscontrollerclass> node of the dnn file, for example:
<Businesscontrollerclass> dnnchina. modules. clinks. clinkscontroller, dnnchina. modules. clinks </businesscontrollerclass>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.