i tried to build a Fileexplorer with the new Treeview Control in ASP.NET 2.0. For navigating it works fine. But when i select a File like a PDF document with spaces in the file-/pathname it doesn't work. When the treeview is generated, the spaces are converted
to %2520 instead of %20.
Sounds like your ' ' is getting double encoded. So the first encoding makes ot %20 and the second encoding encodes the '%' to %25. How are you specifying your paths to the files?
--
Danny
disclaimer: Information provided is 'as is' and conveys no warranties or guarantees.
Class Fileexplorer
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender
As Object,
ByVal e As System.EventArgs)
Handles Me.Load
MyTree.Nodes(0).Expand()
End Sub
Protected Sub MyTree_TreeNodePopulate(ByVal sender
As Object,
ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs)
Handles MyTree.TreeNodePopulate
Dim node As TreeNode = e.Node
If e.Node.Value =
"ITIL" Then
e.Node.Value = Server.MapPath(
"~/IT Manual/" & Request.QueryString("Ordner"))
End If
Dim dirs As
String() = Directory.GetDirectories(e.Node.Value)
'Verzeichnisse
For Each dir
As String
In dirs
Dim newnode
As New TreeNode(Path.GetFileName(dir), dir)
If Directory.GetFiles(dir).Length > 0
OrElse Directory.GetDirectories(dir).Length > 0
Then
newnode.PopulateOnDemand =
True
End If
node.ChildNodes.Add(newnode)
Next
'Dateien
Dim files As
String() = Directory.GetFiles(node.Value)
For Each file
As String
In files
Dim newnode
As New TreeNode(Path.GetFileName(file), file)
newnode.Target =
"_blank"
newnode.NavigateUrl = file
node.ChildNodes.Add(newnode)
Next
End Sub
Strange issue. It looks like the browser is doing the 2nd encoding. If you do a ViewSource on the page, the url is as expected (with a %20). I'm not sure what the workaround would be. I suspect what you would need is to actually not encode the url at
all which I don't think can be done easily.
For a test i have copied the solution to our prodcutive server(Windows 2003, IIS6). On this one there is no error. It seems that error only comes on Windows XP (IIS 5.1) or on the internal IIS from Visual Studio 2005.
I have run into the same problem with space encoding when I try to render graphics files (.jpg, .gif) that I uploaded using the file upload control in Visual Studio (Windows XP Pro). Have you received an answer yet? If so, would you be willing to post
it here?
BN78
Member
25 Points
6 Posts
Treeview NavigateURL with spaces
Mar 17, 2006 12:43 PM|LINK
Hi,
i tried to build a Fileexplorer with the new Treeview Control in ASP.NET 2.0. For navigating it works fine. But when i select a File like a PDF document with spaces in the file-/pathname it doesn't work. When the treeview is generated, the spaces are converted to %2520 instead of %20.
Is this a bug or what is my mistake ?
BN
dannychen
Contributor
4407 Points
840 Posts
AspNetTeam
Re: Treeview NavigateURL with spaces
Mar 17, 2006 08:46 PM|LINK
Sounds like your ' ' is getting double encoded. So the first encoding makes ot %20 and the second encoding encodes the '%' to %25. How are you specifying your paths to the files?
--
Danny
BN78
Member
25 Points
6 Posts
Re: Treeview NavigateURL with spaces
Mar 20, 2006 06:28 AM|LINK
This is my code:
Imports
System.IOPartial
Class Fileexplorer Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadMyTree.Nodes(0).Expand()
End Sub Protected Sub MyTree_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles MyTree.TreeNodePopulate Dim node As TreeNode = e.Node If e.Node.Value = "ITIL" Thene.Node.Value = Server.MapPath(
"~/IT Manual/" & Request.QueryString("Ordner")) End If Dim dirs As String() = Directory.GetDirectories(e.Node.Value) 'Verzeichnisse For Each dir As String In dirs Dim newnode As New TreeNode(Path.GetFileName(dir), dir) If Directory.GetFiles(dir).Length > 0 OrElse Directory.GetDirectories(dir).Length > 0 Thennewnode.PopulateOnDemand =
True End Ifnode.ChildNodes.Add(newnode)
Next 'Dateien Dim files As String() = Directory.GetFiles(node.Value) For Each file As String In files Dim newnode As New TreeNode(Path.GetFileName(file), file)newnode.Target =
"_blank" newnode.NavigateUrl = file node.ChildNodes.Add(newnode) Next End SubEnd
Classdannychen
Contributor
4407 Points
840 Posts
AspNetTeam
Re: Treeview NavigateURL with spaces
Mar 20, 2006 04:49 PM|LINK
Strange issue. It looks like the browser is doing the 2nd encoding. If you do a ViewSource on the page, the url is as expected (with a %20). I'm not sure what the workaround would be. I suspect what you would need is to actually not encode the url at all which I don't think can be done easily.
You can try and file the issue at product feedback and maybe someone would give you better feedback about this issue. http://lab.msdn.microsoft.com/productfeedback
I'm afraid I'm out of ideas on this issue. :(
--
Danny
BN78
Member
25 Points
6 Posts
Re: Treeview NavigateURL with spaces
Mar 21, 2006 11:35 AM|LINK
Petunia
Member
12 Points
4 Posts
Re: Treeview NavigateURL with spaces
Oct 15, 2006 04:00 AM|LINK
I have run into the same problem with space encoding when I try to render graphics files (.jpg, .gif) that I uploaded using the file upload control in Visual Studio (Windows XP Pro). Have you received an answer yet? If so, would you be willing to post it here?
Thanks!