Products

Solutions

Resources

Partners

Community

Blog

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

  • 4/7/2015
  • 5217 Views

Comments

5217 Views

IPortable

Last updated 1 year ago

Comments

Common

(Enter the content of this article below)

Advanced

 

This interface provides module developers a way to allow their modules to import and export content. Modules that support IPortable work well with Page and Portal templates.



To implement IPortable a module must provide an ExportModule implementation and ImportModule implementation. The Format of the STRINGS that are imported/exported is up to the developer, though typically developers will format them with custom XML as the Examples below show.



Example Code (VB)

        '/// -----------------------------------------------------------------------------
        '/// <summary>
        '/// ExportModule implements the IPortable ExportModule Interface
        '/// </summary>
        '/// <param name="ModuleID">The Id of the module to be exported</param>
        '/// -----------------------------------------------------------------------------
        Public Function ExportModule(ByVal ModuleID As Integer) As String Implements IPortable.ExportModule
            Dim strXML As String = ""
            Dim coldnnsimplearticles As List(Of Article) = ArticleController.GetArticles(ModuleID)
            If coldnnsimplearticles.Count <> 0 Then
                strXML += "<articles>"
                For Each objArticle As Article In coldnnsimplearticles
                    strXML += "<article>"
                    strXML += "<title>" + Common.Utilities.XmlUtils.XMLEncode(objArticle.Title) + "</title>"
                    strXML += "<description>" + Common.Utilities.XmlUtils.XMLEncode(objArticle.Description) + "</description>"
                    strXML += "<body>" + Common.Utilities.XmlUtils.XMLEncode(objArticle.Body) + "</body>"
                    strXML += "</article>"
                Next
                strXML += "</articles>"
            End If
            Return strXML
        End Function
        '/// -----------------------------------------------------------------------------
        '/// <summary>
        '/// ImportModule implements the IPortable ImportModule Interface
        '/// </summary>
        '/// <param name="ModuleID">The Id of the module to be imported</param>
        '/// <param name="Content">The content to be imported</param>
        '/// <param name="Version">The version of the module to be imported</param>
        '/// <param name="UserId">The Id of the user performing the import</param>
        '/// -----------------------------------------------------------------------------
        Public Sub ImportModule(ByVal ModuleID As Integer, ByVal Content As String, ByVal Version As String, ByVal UserID As Integer) Implements IPortable.ImportModule
            Dim mc As New ModuleController()
            Dim mi = mc.GetModule(ModuleID)
            Dim xmldnnsimplearticles As XmlNode = DotNetNuke.Common.Globals.GetContent(Content, "articles")
            For Each xmldnnsimplearticle As XmlNode In xmldnnsimplearticles.SelectNodes("article")
                Dim objdnnsimplearticle As New Article()
                objdnnsimplearticle.ModuleId = ModuleID
                objdnnsimplearticle.Title = xmldnnsimplearticle.SelectSingleNode("title").InnerText
                objdnnsimplearticle.Description = xmldnnsimplearticle.SelectSingleNode("description").InnerText
                objdnnsimplearticle.Body = xmldnnsimplearticle.SelectSingleNode("body").InnerText
                objdnnsimplearticle.CreatedByUserId = UserID
                objdnnsimplearticle.CreatedOnDate = DateTime.Now
                objdnnsimplearticle.LastModifiedByUserId = UserID
                objdnnsimplearticle.LastModifiedOnDate = DateTime.Now
                objdnnsimplearticle.Save(mi.TabID)
            Next
        End Sub


Example Code (C#)

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// ExportModule implements the IPortable ExportModule Interface
        /// </summary>
        /// <param name="moduleId">The Id of the module to be exported</param>
        /// -----------------------------------------------------------------------------
        public string ExportModule(int moduleId)
        {
            string strXML = "";
            List<Article> coldnnsimplearticles = ArticleController.GetArticles(moduleId);
            if (coldnnsimplearticles.Count != 0)
            {
                strXML += "<articles>";
                foreach (Article objArticle in coldnnsimplearticles)
                {
                    strXML += "<article>";
                    strXML += "<title>" + Common.Utilities.XmlUtils.XMLEncode(objArticle.Title) + "</title>";
                    strXML += "<description>" + Common.Utilities.XmlUtils.XMLEncode(objArticle.Description) + "</description>";
                    strXML += "<body>" + Common.Utilities.XmlUtils.XMLEncode(objArticle.Body) + "</body>";
                    strXML += "</article>";
                }
                strXML += "</articles>";
            }
            return strXML;
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// ImportModule implements the IPortable ImportModule Interface
        /// </summary>
        /// <param name="moduleId">The Id of the module to be imported</param>
        /// <param name="content">The content to be imported</param>
        /// <param name="version">The version of the module to be imported</param>
        /// <param name="UserId">The Id of the user performing the import</param>
        /// -----------------------------------------------------------------------------
        public void ImportModule(int moduleId, string content, string version, int userId)
        {
            ModuleController mc = new ModuleController();
            var mi = mc.GetModule(moduleId);
            XmlNode xmldnnsimplearticles = DotNetNuke.Common.Globals.GetContent(content, "articles");
            foreach (XmlNode xmldnnsimplearticle in xmldnnsimplearticles.SelectNodes("article"))
            {
                Article objdnnsimplearticle = new Article();
                objdnnsimplearticle.ModuleId = moduleId;
                objdnnsimplearticle.Title = xmldnnsimplearticle.SelectSingleNode("title").InnerText;
                objdnnsimplearticle.Description = xmldnnsimplearticle.SelectSingleNode("description").InnerText;
                objdnnsimplearticle.Body = xmldnnsimplearticle.SelectSingleNode("body").InnerText;
                objdnnsimplearticle.CreatedByUserId = userId;
                objdnnsimplearticle.CreatedOnDate = DateTime.Now;
                objdnnsimplearticle.LastModifiedByUserId = userId;
                objdnnsimplearticle.LastModifiedOnDate = DateTime.Now;
                objdnnsimplearticle.Save(mi.TabID);
            }
        }



Example Code Source

The above sample code can be found on the following Codeplex project http://dnnsimplearticle.codeplex.com
Contents
No sections defined
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out