Welcome Guest Search | Active Topics | Sign In | Register

Populate TreeNode on demand error Options
TonyL
Posted: Sunday, July 27, 2008 11:45:56 PM
Rank: Member
Groups: Member

Joined: 7/26/2008
Posts: 15
Hi,

I encounter an error when populating a node on demand and I found out so far "\n" & "\r" in path value cause the error.

For example:

Two of my TreeView nodes have path value of
"c:\files\11000\newegg\New Folder\"
"c:\files\11000\red ribbon\New Folder\"

If I expand and populate by clicking on the node text, it will populate and expand fine. But if I click on the plus sign (+), I got an error. This is what I saw from tracing the path value of those nodes:

"c:\files\11000 ewegg\New Folder\"
"c:\files\11000 ed ribbon\New Folder\"

The "\n" or "\r" portion is missing

Looks like the client script omitted these characters.


eo_support
Posted: Monday, July 28, 2008 5:36:18 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,193
Hi,

When you say the tree view omits \n and \r, which property are you referering to? Text or ItemID?

Thanks
TonyL
Posted: Monday, July 28, 2008 11:02:56 AM
Rank: Member
Groups: Member

Joined: 7/26/2008
Posts: 15
It's the value of the node. I guess is ItemID. The parentNode.Value below is what contains that value:

Private Sub Explorer_ItemPopulate(ByVal sender As Object, ByVal e As EO.Web.NavigationItemEventArgs) Handles Explorer.ItemPopulate

Dim parentNode As EO.Web.TreeNode = CType(e.NavigationItem, EO.Web.TreeNode)
Dim parentFolder As New DirectoryInfo(parentNode.Value)
For Each subFolder As DirectoryInfo In parentFolder.GetDirectories()

Dim dirNode As New EO.Web.TreeNode(subFolder.Name)
dirNode.Value = parentNode.Value & "\" & subFolder.Name
dirNode.PopulateOnDemand = True

parentNode.SubGroup.Nodes.Add(dirNode)

Next

End Sub
eo_support
Posted: Monday, July 28, 2008 11:11:25 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,193
Hi,

We will take a look of that and get back to you as soon as possible. Value and ItemID are two different things.

Thanks
eo_support
Posted: Monday, July 28, 2008 2:42:05 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,193
Hi,

We tested this feature and it works fine here. Our test code is as follow:

Code: Visual Basic.NET
Dim newNode As New EO.Web.TreeNode

newNode.Text = "abc"
newNode.Value = "abc\r\ndef"

newNode.PopulateOnDemand = True

Dim i As Integer = Microsoft.VisualBasic.Asc(e.TreeNode.Value.Chars(3))

e.TreeNode.ChildNodes.Add(newNode)


The TreeView starts with a single root node with the node's Value property set to any string value that is longer than 3 characters (otherwise e.TreeNode.Value.Chars(3) will fail).

We then set a breakpoint at the last line and run the code. When the breakpoint hits for the first time, ignores it, because the parent node is not the node that we created.

When the break point hits for the second time, watch value i in debugger and you will see a value of 13, which is \r.

What interesting is, the debugger displays e.TreeNode.Value as "abcdef" instead of "abc\r\ndef". However if you watch the value of e.TreeNode.Value.Length, you will see 8, instead of 6.

Thanks
TonyL
Posted: Monday, July 28, 2008 10:31:05 PM
Rank: Member
Groups: Member

Joined: 7/26/2008
Posts: 15
Hum, I see. But if I can't get the correct value from the node, how can I use that value to declare a DirectoryInfo(node.value) object? This is the line where the debugger stops:

Dim parentFolder As New DirectoryInfo(parentNode.Value)

This is where I get the error from and the TreeNode won't expand on demand because of this. Any suggestions?

Thanks.
eo_support
Posted: Monday, July 28, 2008 10:39:25 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,193
Hi,

After a second look of your code:

dirNode.Value = parentNode.Value & "\" & subFolder.Name

It appears that you should be using:

dirNode.Value = parentNode.Value & "\\" & subFolder.Name

When you write "c:\new egg" in your code, you actually get "c:[new line]ew egg" because \n is translated into new line by the compiler. Such escape handling is a part of the language and has nothing to do with our controls.

Thanks
TonyL
Posted: Monday, July 28, 2008 11:08:42 PM
Rank: Member
Groups: Member

Joined: 7/26/2008
Posts: 15
Hi,

"\\" didn't work either, the "\n" part still become a blank space. As I mentioned earlier, if I click on the Text of the node, it returns the correct value, but if I click on the (+) sign, that's where I got the "\n" replaced by space. Should that make any difference which part of the node I click?
eo_support
Posted: Monday, July 28, 2008 11:23:36 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,193
Hi,

You may want to check the source code for this sample:

http://www.essentialobjects.com/Demo/Default.aspx?path=TreeView\_i1\_i1

It demonstrates exactly the same scenario but uses slightly different code, it works perfectly fine. So you may want to copy some code from there.

Frankly speaking, I believe it's your code error in your ItemPopulate handler. That's why when you click the node text it works, but when you click the "+" it doesn't ---- because when you click the "+" your ItemPopulate is called. We have verified and explained that the TreeNode.Value is a transparent value. It stores whatever you give to it. So when it causes an error, it's the value that you give to it is wrong. Troubleshooting user code error would be out of the scope of our support.

Thanks
TonyL
Posted: Tuesday, July 29, 2008 12:23:48 AM
Rank: Member
Groups: Member

Joined: 7/26/2008
Posts: 15
Hum, this is interesting. I tried your code and same problem occurs. Click on Text is fine, but not (+). Here's the complete code, the only thing I change in your ItemPopulate event code is the parentDir value.

By the way, click on both Text and (+) raises the ItemPopulate event.


Code: Visual Basic.NET
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then


            Dim parentNode As New EO.Web.TreeNode("c:\")
            parentNode.Value = "c:\"

            Explorer.TopGroup.Nodes.Add(parentNode)

        End If
End Sub
    
Private Sub Explorer_ItemPopulate(ByVal sender As Object, ByVal e As EO.Web.NavigationItemEventArgs) Handles Explorer.ItemPopulate
        'Get the parent node
        Dim parentNode As EO.Web.TreeNode = CType(e.NavigationItem, EO.Web.TreeNode)

        'Get the root path
        Dim parentDir As String = "c:\"

        'Combine the root path with the node's Value property,
        'in which we stores the relative path to the root
        If parentNode.Value Is Nothing Then
            parentNode.Value = String.Empty
        End If
        parentDir = Path.Combine(parentDir, parentNode.Value)

        'Find all the directories
        Dim dirs As String() = Directory.GetDirectories(parentDir)
        Dim dir As String
        For Each dir In dirs
            Dim dirName As String = Path.GetFileName(dir)
            Dim dirNode As New EO.Web.TreeNode(dirName)

            'Directories can have child items. So at here we
            'store the path associated with this directory to
            'its Value property and set PopulateOnDemand to true
            dirNode.Value = Path.Combine(parentNode.Value, dir)
            dirNode.PopulateOnDemand = True

            parentNode.SubGroup.Nodes.Add(dirNode)
        Next dir

        'Find all files
        Dim files As String() = Directory.GetFiles(parentDir)
        Dim file As String
        For Each file In files
            Dim fileName As String = Path.GetFileName(file)
            Dim fileNode As New EO.Web.TreeNode(fileName)
            parentNode.SubGroup.Nodes.Add(fileNode)
        Next file
    End Sub 'TreeView1_ItemPopulate


eo_support
Posted: Tuesday, July 29, 2008 1:29:15 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,193
Hi,

We have tried your modified code and it runs fine here. So can you let us know:

1. Does the sample code runs fine as is in the sample project?
2. Whats the error message and stack trace for the problem?

Thanks
TonyL
Posted: Tuesday, July 29, 2008 11:33:25 PM
Rank: Member
Groups: Member

Joined: 7/26/2008
Posts: 15
Hi,

I can't find a folder name starting with lower case "n" in your project, therefore I won't know if it works or not.

The error message was "Illegal characters in path."

Here's the exception detail:

System.ArgumentException was unhandled by user code
Message="Illegal characters in path."
Source="mscorlib"
StackTrace:
at System.IO.Path.CheckInvalidPathChars(String path)
at System.IO.Path.Combine(String path1, String path2)
at test_TreeView.Explorer_ItemPopulate(Object sender, NavigationItemEventArgs e) in C:\Inetpub\wwwroot\DAM\test\TreeView.aspx.vb:line 55
at EO.Web.TreeView.a(NavigationItem A_0, String A_1)
at EO.Web.TreeView.a(String A_0, String A_1, String A_2, String A_3, Int32 A_4, String A_5, String A_6, String A_7, Int32 A_8)
at EO.Web.Internal.hj.a(Object A_0, CallbackEventArgs A_1)
at EO.Web.Callback.a(CallbackEventArgs A_0)
at EO.Web.Internal.db.a()
at EO.Web.Internal.b0.a(EventHandler A_0, Boolean A_1)
at EO.Web.Control.b(EventArgs A_0)
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:

Let me know if you need more information.


eo_support
Posted: Wednesday, July 30, 2008 7:38:46 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,193
Hi,

Thanks for the additional information. We have looked into it and it is indeed a bug of our product, not your code error. Please accept our sincere apology for that.

We have fixed the bug and posted a new build. Please see your private message for download location. Please download the new build and let us know how it goes.

Thanks
TonyL
Posted: Thursday, July 31, 2008 6:05:11 AM
Rank: Member
Groups: Member

Joined: 7/26/2008
Posts: 15

No problem.

Thanks for the fix, it works now.

TonyL
Posted: Tuesday, August 5, 2008 3:33:48 AM
Rank: Member
Groups: Member

Joined: 7/26/2008
Posts: 15
Hi,

I found out another problem on the similar issue. "\1" is replaced by "<". This is another one I encounter so far. This only happens when click on the (+).
eo_support
Posted: Tuesday, August 5, 2008 6:56:41 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,193
Hi,

Thank you very much for the information. We will look into it and see what we can find.

Thanks
eo_support
Posted: Thursday, August 7, 2008 6:18:51 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,193
Hi,

We've posted a new build that addressed this issue. Please check your private message for download location.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.