Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. special characters?

special characters?

Scheduled Pinned Locked Moved ASP.NET
question
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mayl
    wrote on last edited by
    #1

    Hi I'm trying to do a create a datagrid to list files on a remote shared. My files'names contain special characters such as the # sign. Below is the code that I used to generate my data table. The filenames are displayed correctly. However, the link did not work. Ex: if my filename is "xxx # xxx.tif", the link is \\fileserver\shared\xxx. Any ideas? Function createDataSource() As ICollection Dim objDirInfo As New DirectoryInfo("\\fileserver\shared") Dim file As FileInfo Dim objDV As DataView Dim objDS As DataSet = New DataSet Dim objDT As DataTable = New DataTable("Files") Dim objDR As DataRow objDT.Columns.Add("Filename", GetType(String)) Try Dim fileInfos() As FileInfo = objDirInfo.GetFiles("*.*") Dim fileLength As Integer = fileInfos.Length If fileLength > 0 Then 'file(s) found For Each file In fileInfos objDR = objDT.NewRow() objDR(0) = "[" & file.Name & "](" & file.FullName & ")" objDT.Rows.Add(objDR) Next objDS.Tables.Add(objDT) objDV = New DataView(objDS.Tables("Files")) objDV.Sort = "Filename asc" createDataSource = objDV End If Catch ex As Exception End Try End Function thank you

    M G 2 Replies Last reply
    0
    • M mayl

      Hi I'm trying to do a create a datagrid to list files on a remote shared. My files'names contain special characters such as the # sign. Below is the code that I used to generate my data table. The filenames are displayed correctly. However, the link did not work. Ex: if my filename is "xxx # xxx.tif", the link is \\fileserver\shared\xxx. Any ideas? Function createDataSource() As ICollection Dim objDirInfo As New DirectoryInfo("\\fileserver\shared") Dim file As FileInfo Dim objDV As DataView Dim objDS As DataSet = New DataSet Dim objDT As DataTable = New DataTable("Files") Dim objDR As DataRow objDT.Columns.Add("Filename", GetType(String)) Try Dim fileInfos() As FileInfo = objDirInfo.GetFiles("*.*") Dim fileLength As Integer = fileInfos.Length If fileLength > 0 Then 'file(s) found For Each file In fileInfos objDR = objDT.NewRow() objDR(0) = "[" & file.Name & "](" & file.FullName & ")" objDT.Rows.Add(objDR) Next objDS.Tables.Add(objDT) objDV = New DataView(objDS.Tables("Files")) objDV.Sort = "Filename asc" createDataSource = objDV End If Catch ex As Exception End Try End Function thank you

      M Offline
      M Offline
      mayl
      wrote on last edited by
      #2

      Function createDataSource() As ICollection Dim objDirInfo As New DirectoryInfo("\\fileserver\shared") Dim file As FileInfo Dim objDV As DataView Dim objDS As DataSet = New DataSet Dim objDT As DataTable = New DataTable("Files") Dim objDR As DataRow objDT.Columns.Add("Filename", GetType(String)) Try Dim fileInfos() As FileInfo = objDirInfo.GetFiles("*.*") Dim fileLength As Integer = fileInfos.Length If fileLength > 0 Then 'file(s) found For Each file In fileInfos objDR = objDT.NewRow() objDR(0) = "[" & file.Name & "](" & Server.HtmlEncode(file.FullName) & ")" objDT.Rows.Add(objDR) Next objDS.Tables.Add(objDT) objDV = New DataView(objDS.Tables("Files")) objDV.Sort = "Filename asc" createDataSource = objDV End If

      1 Reply Last reply
      0
      • M mayl

        Hi I'm trying to do a create a datagrid to list files on a remote shared. My files'names contain special characters such as the # sign. Below is the code that I used to generate my data table. The filenames are displayed correctly. However, the link did not work. Ex: if my filename is "xxx # xxx.tif", the link is \\fileserver\shared\xxx. Any ideas? Function createDataSource() As ICollection Dim objDirInfo As New DirectoryInfo("\\fileserver\shared") Dim file As FileInfo Dim objDV As DataView Dim objDS As DataSet = New DataSet Dim objDT As DataTable = New DataTable("Files") Dim objDR As DataRow objDT.Columns.Add("Filename", GetType(String)) Try Dim fileInfos() As FileInfo = objDirInfo.GetFiles("*.*") Dim fileLength As Integer = fileInfos.Length If fileLength > 0 Then 'file(s) found For Each file In fileInfos objDR = objDT.NewRow() objDR(0) = "[" & file.Name & "](" & file.FullName & ")" objDT.Rows.Add(objDR) Next objDS.Tables.Add(objDT) objDV = New DataView(objDS.Tables("Files")) objDV.Sort = "Filename asc" createDataSource = objDV End If Catch ex As Exception End Try End Function thank you

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        You have to url-encode the filename to use it as an url. Use the Server.UrlEncode method. --- b { font-weight: normal; }

        M 2 Replies Last reply
        0
        • G Guffa

          You have to url-encode the filename to use it as an url. Use the Server.UrlEncode method. --- b { font-weight: normal; }

          M Offline
          M Offline
          mayl
          wrote on last edited by
          #4

          I tried it and it did encode. If the file is on my web server, it will be fine. However, the file that I'm trying to open is on a different server. thanks

          G 1 Reply Last reply
          0
          • G Guffa

            You have to url-encode the filename to use it as an url. Use the Server.UrlEncode method. --- b { font-weight: normal; }

            M Offline
            M Offline
            mayl
            wrote on last edited by
            #5

            I mean it did not encode. thanks

            1 Reply Last reply
            0
            • M mayl

              I tried it and it did encode. If the file is on my web server, it will be fine. However, the file that I'm trying to open is on a different server. thanks

              G Offline
              G Offline
              Guffa
              wrote on last edited by
              #6

              Well, if it didn't get encoded, you obviously did not use it correctly. The UrlEncode method returns the encoded string. string unencoded = "hello there"; string encoded = Server.UrlEncode(unencoded); the string encoded now contains "hello%20there". --- b { font-weight: normal; }

              M 1 Reply Last reply
              0
              • G Guffa

                Well, if it didn't get encoded, you obviously did not use it correctly. The UrlEncode method returns the encoded string. string unencoded = "hello there"; string encoded = Server.UrlEncode(unencoded); the string encoded now contains "hello%20there". --- b { font-weight: normal; }

                M Offline
                M Offline
                mayl
                wrote on last edited by
                #7

                I apologize for not being clear. What I was trying to say is that "[" & file.Name & "](" & Server.UrlEncode(file.FullName) & ")" gives me page cannot be found message. I'm trying to open a file on a separate file server: \\server\shared\file#file.tif Instead I get http://host/home/\\server\sharedfile%23.tif thanks

                G 1 Reply Last reply
                0
                • M mayl

                  I apologize for not being clear. What I was trying to say is that "[" & file.Name & "](" & Server.UrlEncode(file.FullName) & ")" gives me page cannot be found message. I'm trying to open a file on a separate file server: \\server\shared\file#file.tif Instead I get http://host/home/\\server\sharedfile%23.tif thanks

                  G Offline
                  G Offline
                  Guffa
                  wrote on last edited by
                  #8

                  You should only encode the file name, not the entire path. --- b { font-weight: normal; }

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups