Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

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!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Building a DNNTree from XML File [Solved using PopulateOnDemand]Building a DNNTree from XML File [Solved using PopulateOnDemand]
Previous
 
Next
New Post
2/2/2007 7:07 PM
 
Hello !
I'm trying to make a DNNTree for displaying folders on my hard disk.
I can't make it works for two reasons :
- The XML seemed to be mal formed,
- I don't really know how to do with the WriteEndElement, i may use a pile but ... how to ?

Here my code, and at the end, the exception i get.

Sébastien

----------------------------------------------CODE----------------------------------------------
Public _myId As Integer
        Public Property myId() As Integer
            Get
                If _myId <> Nothing Then
                    Return _myId
                Else
                    Return 0
                End If
            End Get
            Set(ByVal value As Integer)
                _myId = value
            End Set
End Property

Public Sub buildXMLTreeSubLevels(ByVal _path As String, ByVal monXmlWriter As XmlWriter)

            Dim folders As String()
            folders = Directory.GetDirectories(_path)

            Dim folder As String
            Dim objFile As IO.FileInfo
            Dim objFolder As DirectoryInfo

            For Each folder In folders

                objFolder = New System.IO.DirectoryInfo(folder)

                monXmlWriter.WriteStartElement("n")
                myId = myId + 1
                monXmlWriter.WriteAttributeString("id", myId)
                monXmlWriter.WriteAttributeString("txt", objFolder.Name)
                monXmlWriter.WriteAttributeString("img", "../../../Images/folder.gif")
                monXmlWriter.WriteAttributeString("ca", 1)

                Dim subFolders As String() = Directory.GetDirectories(folder)
                If Not subFolders.Length <> Nothing Then ' The folder don't have any sub folder
                    If Not objFolder.GetFiles("*.txt").Length <> Nothing Then ' The folder don't have a txt file
                        monXmlWriter.WriteAttributeString("hasNodes", "0")
                    Else
                        monXmlWriter.WriteAttributeString("hasNodes", "1")
                    End If
                Else
                    monXmlWriter.WriteAttributeString("hasNodes", "1")
                    buildXMLTreeSubLevels(folder, monXmlWriter)
                End If

                ' Look for TXT files
                For Each objFile In objFolder.GetFiles("*.txt")
                    Dim strLocalNFOFile As String = PortalSettings.HomeDirectoryMapPath & "\LocalesTXT\" & objFolder.Name & objFile.Name
                    If Not File.Exists(strLocalNFOFile) Then
                        File.Copy(objFile.FullName, strLocalNFOFile)
                    End If
                   ' TODO: Transform to non-static method using something like
                    'Dim objFileController As New DotNetNuke.Services.FileSystem.FileController
                    'Dim fileId As Integer = objFileController.ConvertFilePathToFileId(objFile.FullName, PortalId)
                    'Dim objFileInfo As DotNetNuke.Services.FileSystem.FileInfo = objFileController.GetFileById(fileId, PortalId)
                    monXmlWriter.WriteStartElement("n")
                    myId = myId + 1
                    monXmlWriter.WriteAttributeString("id", myId)
                    monXmlWriter.WriteAttributeString("txt", objFile.Name)
                    monXmlWriter.WriteAttributeString("img", "../../../Images/file.gif")
                    monXmlWriter.WriteAttributeString("ca", 3)
                    monXmlWriter.WriteAttributeString("url", "http://hard-coded-IP/Portals/0/LocalesTXT/" & objFolder.Name & objFile.Name) ' TODO: Transform to non-static method
                    monXmlWriter.WriteAttributeString("tar", "_blank")
                    monXmlWriter.WriteEndElement()
                Next
                monXmlWriter.WriteEndElement()

            Next
            monXmlWriter.WriteEndElement()
End Sub



        Public Sub buildXMLTree() 'First method called

            ' ----------- INIT FOLDERS
            Dim folders As String()
          
            folders = Directory.GetDirectories("Z:\SharedData\")' TODO: Transform to non-static method from module settings

            ' ----------- INIT XML BUILDER
            Dim portalsXmlFilesPath As String = PortalSettings.HomeDirectoryMapPath & "DNNTreeXMLs"
            If Not Directory.Exists(portalsXmlFilesPath) Then
                Directory.CreateDirectory(portalsXmlFilesPath)
            End If

            Dim monFileName As String = portalsXmlFilesPath & "\" & "DNNTree_" & Me.ModuleId & ".xml"

            Dim monXmlWriter As New XmlTextWriter(monFileName, Text.Encoding.UTF8)
            monXmlWriter.Formatting = Formatting.Indented

            monXmlWriter.WriteStartElement("root")
            monXmlWriter.WriteAttributeString("id", "DNNTree") ' TODO: Transform to non-static method

            Dim folder As String
            Dim objFile As IO.FileInfo
            Dim objFolder As DirectoryInfo

            Dim count As Integer = 0

            ' Look for sub folders
            For Each folder In folders

                objFolder = New System.IO.DirectoryInfo(folder)

                monXmlWriter.WriteStartElement("n")
                If count = 0 Then ' IDs starts from 0
                    myId = 0
                    count = 1
                Else
                    myId = myId + 1
                End If

                monXmlWriter.WriteAttributeString("id", myId)
                monXmlWriter.WriteAttributeString("txt", objFolder.Name)
                monXmlWriter.WriteAttributeString("img", "../../../Images/folder.gif")
                monXmlWriter.WriteAttributeString("ca", 1)

                Dim subFolders As String() = Directory.GetDirectories(folder)
                If Not subFolders.Length <> Nothing Then
                    If Not objFolder.GetFiles("*.txt").Length <> Nothing Then
                        monXmlWriter.WriteAttributeString("hasNodes", "0")
                    Else
                        monXmlWriter.WriteAttributeString("hasNodes", "1")
                    End If
                Else
                    monXmlWriter.WriteAttributeString("hasNodes", "1")
                End If

                ' Look for TXT files
                For Each objFile In objFolder.GetFiles("*.txt")
                    Dim strLocalNFOFile As String = PortalSettings.HomeDirectoryMapPath & "LocalesTXT\" & objFolder.Name & objFile.Name
                    If Not File.Exists(strLocalNFOFile) Then
                        File.Copy(objFile.FullName, strLocalNFOFile)
                    End If
                    ' TODO: Transform to non-static method using something like
                    'Dim objFileController As New DotNetNuke.Services.FileSystem.FileController
                    'Dim fileId As Integer = objFileController.ConvertFilePathToFileId(objFile.FullName, PortalId)
                    'Dim objFileInfo As DotNetNuke.Services.FileSystem.FileInfo = objFileController.GetFileById(fileId, PortalId)
                    monXmlWriter.WriteStartElement("n")
                    myId = myId + 1
                    monXmlWriter.WriteAttributeString("id", myId)
                    monXmlWriter.WriteAttributeString("txt", objFile.Name)
                    monXmlWriter.WriteAttributeString("img", "../../../Images/file.gif")
                    monXmlWriter.WriteAttributeString("ca", 3)
                    monXmlWriter.WriteAttributeString("url", "http://hard-coded-IP/Portals/0/LocalesTXT/" & objFolder.Name & objFile.Name)
                    monXmlWriter.WriteAttributeString("tar", "_blank")
                    monXmlWriter.WriteEndElement()
                Next

                buildXMLTreeSubLevels(folder, monXmlWriter) ' recursive method
                monXmlWriter.WriteEndElement()

            Next
            monXmlWriter.WriteEndElement()

            monXmlWriter.Flush()

            monXmlWriter.Close()

            DNNTree.LoadXml(monFileName)

End Sub
---------------------------------------------------------------------------------------------------

------------------------------------------------EXC----------------------------------------------
DotNetNuke.Services.Exceptions.ModuleLoadException: Data at the root level is invalid. Line 1, position 1.
--->
System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.
at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.LoadXml(String xml)
at DotNetNuke.UI.WebControls.XmlCollectionBase..ctor(String strXML, String strXSLFile)
at DotNetNuke.UI.WebControls.DNNNodeCollection..ctor(String strXML, String strXSLFile)
at DotNetNuke.UI.WebControls.TreeNodeCollection..ctor(String strXML, String strXSLFile, DnnTree objControl)
at DotNetNuke.UI.WebControls.DnnTree.LoadXml(String strXml)
at Aricie.Modules.TestSharedDataManager.ViewTestSharedDataManager.buildXMLTree()
in Z:\Sites Web\Developpement\440\Website\DesktopModules\TestSharedDataManager\ViewTestSharedDataManager.ascx.vb:line 340
at Aricie.Modules.TestSharedDataManager.ViewTestSharedDataManager.Page_Load(Object sender, EventArgs e)
in Z:\Sites Web\Developpement\440\Website\DesktopModules\TestSharedDataManager\ViewTestSharedDataManager.ascx.vb:line 394
--- End of inner exception stack trace ---
---------------------------------------------------------------------------------------------------
------------------------------------------------EXC#2----------------------------------------------
DotNetNuke.Services.Exceptions.ModuleLoadException:
There was no XML start tag open.
--->
System.InvalidOperationException: There was no XML start tag open.
at System.Xml.XmlTextWriter.InternalWriteEndElement(Boolean longFormat)
at System.Xml.XmlTextWriter.WriteEndElement()
at Aricie.Modules.TestSharedDataManager.ViewTestSharedDataManager.buildXMLTreeSubLevels(String _path, XmlWriter monXmlWriter)
in Z:\Sites Web\Developpement\440\Website\DesktopModules\TestSharedDataManager\ViewTestSharedDataManager.ascx.vb:line 237
at Aricie.Modules.TestSharedDataManager.ViewTestSharedDataManager.buildXMLTree()
in Z:\Sites Web\Developpement\440\Website\DesktopModules\TestSharedDataManager\ViewTestSharedDataManager.ascx.vb:line 323
at Aricie.Modules.TestSharedDataManager.ViewTestSharedDataManager.Page_Load(Object sender, EventArgs e)
in Z:\Sites Web\Developpement\440\Website\DesktopModules\TestSharedDataManager\ViewTestSharedDataManager.ascx.vb:line 386
--- End of inner exception stack trace ---
---------------------------------------------------------------------------------------------------

The French Language pack for fr-FR is available at www.dnn-fr.org
 
New Post
2/3/2007 5:34 AM
 
Anyone had already build a DNNTree using a XML File ?

Sébastien - FRANCE

The French Language pack for fr-FR is available at www.dnn-fr.org
 
New Post
2/3/2007 2:47 PM
 
Finally i've done in another manner. I've used the PopulateOnDemand method explained in Dotnetnuke.Webcontrols.Test propject.

<DNN:DNNTree id="MyDNNTree" runat="server"  TreeScriptPath="http://localhost/DesktopModules/WebControlsTestComponents/js/"
                                    DefaultNodeCssClassSelected="SelClass" ExpandedNodeImage="Images/ElementMinus.jpg" CollapsedNodeImage="Images/ElementPlus.jpg"
                                    DefaultNodeCssClassOver="HoverClass" DefaultNodeCssClass="NodeDefault" DefaultChildNodeCssClass="ChildNodeDefault"
                                    DefaultIconCssClass="NodeIconDefault" IndentWidth="100" ExpandCollapseImageWidth="9" PopulateNodesFromClient="True"></DNN:DNNTree>


 Private Sub PopulateTree(ByVal strPath As String)
            MyDNNTree.TreeNodes.Clear()

            Dim objNode As DotNetNuke.UI.WebControls.TreeNode = New TreeNode("root")
            objNode.Key = strPath
            objNode.ToolTip = objNode.Text
            objNode.ImageIndex = eImageType.Folder
            objNode.ClickAction = eClickAction.Expand
            objNode.HasNodes = True
            MyDNNTree.TreeNodes.Add(objNode)
            If Me.MyDNNTree.PopulateNodesFromClient = False Then PopulateChildrenTreeNodes(objNode)

        End Sub

        Private Sub PopulateChildrenTreeNodes(ByVal objParent As TreeNode)
            Dim strKey As String = objParent.Key
            If strKey.EndsWith("\") = False Then strKey &= "\"
            'If strKey.IndexOf(Request.MapPath("")) = -1 Then ' Removed, my directory is outside the APP base dir
            '    Return
            'End If
            Dim files As String() = Directory.GetFileSystemEntries(strKey)
            Dim index As Integer = 0
            While index < files.Length
                Dim objFileInfo As FileInfo = New FileInfo(files(index))
                Dim objTreeNode As TreeNode
                Dim intIndex As Integer
                If objParent Is Nothing Then
                    If objFileInfo.Extension = "nfo" Or (File.GetAttributes(files(index)) And FileAttributes.Directory) = FileAttributes.Directory Then ' filter the txt files and the directories
                        intIndex = MyDNNTree.TreeNodes.Add()
                        objTreeNode = MyDNNTree.TreeNodes(intIndex)
                    End If
                Else
                    If objFileInfo.Extension = "txt" Or (File.GetAttributes(files(index)) And FileAttributes.Directory) = FileAttributes.Directory Then ' filter the txt files and the directories
                        intIndex = objParent.TreeNodes.Add()
                        objTreeNode = objParent.TreeNodes(intIndex)
                    End If
                End If

                objTreeNode.Text = objFileInfo.Name
                objTreeNode.Key = objFileInfo.FullName
                objTreeNode.ToolTip = objFileInfo.Name


                If objTreeNode.Key.EndsWith(".txt") Then
                    objTreeNode.JSFunction = "openPopup(" & objFileInfo.Name & ", 0);"
                    objTreeNode.CssClass = "SpecialNode"
                    objTreeNode.CssClassOver = "SpecialNodeHover"
                End If

                If (File.GetAttributes(files(index)) And FileAttributes.Directory) = FileAttributes.Directory Then
                    objTreeNode.ImageIndex = eImageType.Folder
                    'if we are not populating from client we need to populate all the treenodes now
                    If Me.MyDNNTree.PopulateNodesFromClient = False Then PopulateChildrenTreeNodes(objTreeNode)

                    Try
                        Dim objDir As DirectoryInfo = New DirectoryInfo(objFileInfo.FullName)
                        objTreeNode.HasNodes = objDir.GetFiles.Length > 0 OrElse objDir.GetDirectories.Length > 0
                        objTreeNode.ClickAction = eClickAction.Expand
                    Catch ex As Exception
                    End Try

                Else
                   
                    objTreeNode.ImageIndex = eImageType.Page
                End If
                index += 1
            End While
        End Sub


 Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender

        End Sub


        Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
            MyBase.OnInit(e)
            DotNetNuke.UI.Utilities.ClientAPI.HandleClientAPICallbackEvent(Me.Page)
        End Sub

        Private Sub MyDNNTree_PopulateOnDemand(ByVal source As Object, ByVal e As DotNetNuke.UI.WebControls.DNNTreeEventArgs) Handles MyDNNTree.PopulateOnDemand
            PopulateChildrenTreeNodes(e.Node)
        End Sub

        Private Sub MyDNNTree_NodeClick(ByVal source As Object, ByVal e As DNNTreeNodeClickEventArgs) Handles MyDNNTree.NodeClick

' Function J# opening a popup with the TXT content

        End Sub

On page_Load:
' configure tree
                    Me.MyDNNTree.SystemImagesPath = ResolveUrl("~/images/")
                    Me.MyDNNTree.ImageList.Add(ResolveUrl("~/images/folder.gif"))
                    Me.MyDNNTree.ImageList.Add(ResolveUrl("~/images/file.gif"))
                    Me.MyDNNTree.IndentWidth = 10
                    Me.MyDNNTree.CollapsedNodeImage = ResolveUrl("~/images/max.gif")
                    Me.MyDNNTree.ExpandedNodeImage = ResolveUrl("~/images/min.gif")

                    Me.MyDNNTree.PopulateNodesFromClient = True
                  '  Me.MyDNNTree.JSFunction = "myTestFunction('TestParam1', 'TestParam2');"
                    Me.MyDNNTree.Target = "MyTarget"

                    PopulateTree("Z:\Data\")

The French Language pack for fr-FR is available at www.dnn-fr.org
 
New Post
2/3/2007 2:53 PM
 
If someone is looking for building a XML file from a list of folders and subfolders, i've done this code :

Private xmlDoc As XmlDocument
  Public Function GetFileSystemInfoList(ByVal StartFolder As String) As XmlDocument
            Try
                Dim declaration1 As XmlDeclaration = Me.xmlDoc.CreateXmlDeclaration("1.0", "", "yes")
                Me.xmlDoc.PrependChild(declaration1)
                Dim element1 As XmlElement = Me.XmlElement("n", New DirectoryInfo(StartFolder).Name)
                Me.xmlDoc.AppendChild(Me.AddElements(element1, StartFolder))
            Catch exception1 As Exception
                Me.xmlDoc.AppendChild(Me.XmlElement("error", exception1.Message))
                Return Me.xmlDoc
            End Try
            Return Me.xmlDoc
        End Function

Private Function AddElements(ByVal startNode As XmlElement, ByVal Folder As String) As XmlElement
            Try
                Dim info1 As New DirectoryInfo(Folder)
                Dim infoArray1 As DirectoryInfo() = info1.GetDirectories
                Dim infoArray2 As FileInfo() = info1.GetFiles
                Dim info2 As FileInfo
                Dim count As Integer = 0
                For Each info2 In infoArray2
                    If info2.Extension = ".txt" Then 'Filter the TXT Files
                        Dim element1 As XmlElement = Me.XmlElement("name", info2.Name)
                        ' Add attributes :
                        ' element1.Attributes.Append(Me.XmlAttribute("Name of the attribute", "Value of the attribute"))
                        startNode.AppendChild(element1)
                     
                    End If

                Next
                Dim info3 As DirectoryInfo
                For Each info3 In infoArray1
                    Dim element2 As XmlElement = Me.XmlElement("n", info3.Name)
                    element2.Attributes.Append(Me.XmlAttribute("name", info3.Name))
                    ' any other attributes here             

                    startNode.AppendChild(Me.AddElements(element2, info3.FullName))
                Next
                Return startNode
            Catch exception1 As Exception
                Return Me.XmlElement("error", exception1.Message)
            End Try
        End Function
Private Function FilterXMLString(ByVal inputString As String) As String
            Dim text1 As String = inputString
            If (inputString.IndexOf("&") > 0) Then
                text1 = inputString.Replace("&", "&amp;")
            End If
            If (inputString.IndexOf("'") > 0) Then
                text1 = inputString.Replace("'", "&apos;")
            End If
            Return text1
        End Function

        Private Function XmlAttribute(ByVal attributeName As String, ByVal attributeValue As String) As XmlAttribute
            Dim attribute1 As XmlAttribute = Me.xmlDoc.CreateAttribute(attributeName)
            attribute1.Value = Me.FilterXMLString(attributeValue)
            Return attribute1
        End Function

        Private Function XmlElement(ByVal elementName As String, ByVal elementValue As String) As XmlElement
            Dim element1 As XmlElement = Me.xmlDoc.CreateElement(elementName)
            element1.Attributes.Append(Me.XmlAttribute("name", Me.FilterXMLString(elementValue)))
            Return element1
        End Function

The French Language pack for fr-FR is available at www.dnn-fr.org
 
New Post
2/3/2007 3:09 PM
 

Sébastien wrote
If someone is looking for building a XML file from a list of folders and subfolders,

Thank you for the contribution, it is appreciated. For more on the DNN Tree control see: http://webcontrols.dotnetnuke.com/DNNTree.aspx and DnnTree



Michael Washington
http://ADefWebserver.com
www.ADefHelpDesk.com
A Free Open Source DotNetNuke Help Desk Module
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Building a DNNTree from XML File [Solved using PopulateOnDemand]Building a DNNTree from XML File [Solved using PopulateOnDemand]


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out