spaces in file paths

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DesCF

    #1

    spaces in file paths

    The following doesn't work:

    Dim photoPath As String = "R:\My Documents\My Pictures\MiscLL \"

    It doesn't work if I use double quotes either. It does work if I use a
    different path without spaces in it. What is the simple solution ?



    --
    Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
  • Eric Moreau

    #2
    Re: spaces in file paths

    concatenate double quotes around it:

    Dim photoPath As String = chr(34) + "R:\My Documents\My Pictures\MiscLL \" +
    chr(34)


    --


    HTH

    Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
    Conseiller Principal / Senior Consultant
    S2i web inc. (www.s2i.com)


    "DesCF" <descf@aol.comw rote in message news:op.tkplbpv rupgxg0@descsta r...
    The following doesn't work:

    Dim photoPath As String = "R:\My Documents\My Pictures\MiscLL \"

    It doesn't work if I use double quotes either. It does work if I use a
    different path without spaces in it. What is the simple solution ?



    --
    Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


    Comment

    • Tom Leylan

      #3
      Re: spaces in file paths

      I'd be shocked if that didn't work. It doesn't assign that string to the
      photoPath variable?

      "DesCF" <descf@aol.comw rote in message news:op.tkplbpv rupgxg0@descsta r...
      The following doesn't work:

      Dim photoPath As String = "R:\My Documents\My Pictures\MiscLL \"

      It doesn't work if I use double quotes either. It does work if I use a
      different path without spaces in it. What is the simple solution ?



      --
      Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: spaces in file paths

        "DesCF" <descf@aol.coms chrieb:
        >The following doesn't work:
        >
        >Dim photoPath As String = "R:\My Documents\My Pictures\MiscLL \"
        >
        >It doesn't work if I use double quotes either. It does work if I use a
        >different path without spaces in it. What is the simple solution ?
        What does not work?!

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

        Comment

        • DesCF

          #5
          Re: spaces in file paths

          Right, the code for the entire web page is below.

          If I create a directory J:\Fots and stick some photos in it, it works just
          fine. If I change the directory name to J:\Fot s (i.e. insert a space
          between the t and the s) it just displays the placeholders for the right
          number of photos with little red X's in them.


          <%@ Page Language="VB" %>
          <%@ Import Namespace="Syst em.IO" %>
          <%@ Import Namespace="Syst em.Collections. Generic" %>

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
          "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
          <script runat="server">

          ''' <summary>
          ''' Bind photos to Repeater
          ''' </summary>
          Sub Page_Load()
          If Not Page.IsPostBack Then
          Repeater1.DataS ource = GetPhotos()
          Repeater1.DataB ind()
          End If
          End Sub

          ''' <summary>
          ''' Get list of photos from Photo folder
          ''' </summary>
          Public Function GetPhotos() As List(Of String)
          Dim photos As New List(Of String)()
          Dim photoPath As String = "J:\Fot s\"
          Dim files As String() = Directory.GetFi les(photoPath)
          For Each photo As String In files
          photos.Add(phot oPath + Path.GetFileNam e(photo))
          Next
          Return photos
          End Function

          </script>
          <html xmlns="http://www.w3.org/1999/xhtml" >
          <head id="Head1" runat="server">
          <title>Show Photos</title>
          </head>
          <body>
          <form id="form1" runat="server">
          <div>

          <asp:Repeater
          id="Repeater1"
          runat="server">
          <ItemTemplate >
          <asp:Image
          id="Image1"
          Width="200px"
          ImageUrl='<%# Container.DataI tem %>'
          Runat="server" />
          </ItemTemplate>
          </asp:Repeater>

          </div>
          </form>
          </body>
          </html>



          ---


          On Sun, 17 Dec 2006 15:00:51 -0000, DesCF <descf@aol.comw rote:
          The following doesn't work:
          >
          Dim photoPath As String = "R:\My Documents\My Pictures\MiscLL \"
          >
          It doesn't work if I use double quotes either. It does work if I use a
          different path without spaces in it. What is the simple solution ?
          >
          >
          >


          --
          Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

          Comment

          • DesCF

            #6
            Re: spaces in file paths

            I tried this and I get an invalid characters in path error. Thanks for
            the suggestion anyrate.


            On Sun, 17 Dec 2006 16:18:30 -0000, Eric Moreau
            <eric.moreau_N_ O_S_P_A_M@video tron.cawrote:
            concatenate double quotes around it:
            >
            Dim photoPath As String = chr(34) + "R:\My Documents\My
            Pictures\MiscLL \" +
            chr(34)
            >
            >


            --
            Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

            Comment

            • RobinS

              #7
              Re: spaces in file paths

              What are you trying to do with it; how are you trying to use it?
              Post more of your code, and maybe we can help you with it.

              Robin S.
              ------------------------------
              "DesCF" <descf@aol.comw rote in message
              news:op.tkptgf1 aupgxg0@descsta r...
              I tried this and I get an invalid characters in path error. Thanks for
              the suggestion anyrate.


              On Sun, 17 Dec 2006 16:18:30 -0000, Eric Moreau
              <eric.moreau_N_ O_S_P_A_M@video tron.cawrote:
              concatenate double quotes around it:
              >
              Dim photoPath As String = chr(34) + "R:\My Documents\My
              Pictures\MiscLL \" +
              chr(34)
              >
              >


              --
              Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


              Comment

              • Cor Ligthert [MVP]

                #8
                Re: spaces in file paths

                Tom,

                This is not in every country the same, here in Holland I have

                C:\Documents and Settings\cor\Mi jn documenten\Mijn afbeeldingen

                I thought that Herfried had that Document and Settings in the German
                language as well.

                However this is as well working here.

                Environment.Spe cialFolder.MyPi ctures

                I know that you knew this.

                :-)

                Cor

                Therefore Environment.
                "Tom Leylan" <tleylan@nospam .netschreef in bericht
                news:Oo2qjefIHH A.4760@TK2MSFTN GP03.phx.gbl...
                I'd be shocked if that didn't work. It doesn't assign that string to the
                photoPath variable?
                >
                "DesCF" <descf@aol.comw rote in message
                news:op.tkplbpv rupgxg0@descsta r...
                The following doesn't work:
                >
                Dim photoPath As String = "R:\My Documents\My Pictures\MiscLL \"
                >
                It doesn't work if I use double quotes either. It does work if I use a
                different path without spaces in it. What is the simple solution ?
                >
                >
                >
                --
                Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
                >

                Comment

                • Cor Ligthert [MVP]

                  #9
                  Re: spaces in file paths

                  Herfried,

                  Sie auch, unglaublich?

                  :-)

                  Cor

                  "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atschr eef in bericht
                  news:%23wdvglfI HHA.4992@TK2MSF TNGP04.phx.gbl. ..
                  "DesCF" <descf@aol.coms chrieb:
                  >>The following doesn't work:
                  >>
                  >>Dim photoPath As String = "R:\My Documents\My Pictures\MiscLL \"
                  >>
                  >>It doesn't work if I use double quotes either. It does work if I use a
                  >>different path without spaces in it. What is the simple solution ?
                  >
                  What does not work?!
                  >
                  --
                  M S Herfried K. Wagner
                  M V P <URL:http://dotnet.mvps.org/>
                  V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                  Comment

                  • Cor Ligthert [MVP]

                    #10
                    Re: spaces in file paths

                    Des

                    if it is your own map, than it is mostly

                    Environment.Spe cialFolder.MyPi ctures

                    Cor

                    "DesCF" <descf@aol.coms chreef in bericht
                    news:op.tkplbpv rupgxg0@descsta r...
                    The following doesn't work:

                    Dim photoPath As String = "R:\My Documents\My Pictures\MiscLL \"

                    It doesn't work if I use double quotes either. It does work if I use a
                    different path without spaces in it. What is the simple solution ?



                    --
                    Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


                    Comment

                    • Herfried K. Wagner [MVP]

                      #11
                      Re: spaces in file paths

                      Cor,

                      "Cor Ligthert [MVP]" <notmyfirstname @planet.nlschri eb:
                      This is not in every country the same, here in Holland I have
                      >
                      C:\Documents and Settings\cor\Mi jn documenten\Mijn afbeeldingen
                      >
                      I thought that Herfried had that Document and Settings in the German
                      language as well.
                      It's "C:\Dokumen te und Einstellungen\. ..\Eigene Dokumente\Eigen e Bilder" on
                      my German version of Windows XP.

                      --
                      M S Herfried K. Wagner
                      M V P <URL:http://dotnet.mvps.org/>
                      V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                      Comment

                      • Tom Leylan

                        #12
                        Re: spaces in file paths

                        Hi Cor:

                        I don't believe the assignment of either string would fail in any country
                        :-)


                        "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
                        news:%23VGWiFhI HHA.1816@TK2MSF TNGP06.phx.gbl. ..
                        Tom,
                        >
                        This is not in every country the same, here in Holland I have
                        >
                        C:\Documents and Settings\cor\Mi jn documenten\Mijn afbeeldingen
                        >
                        I thought that Herfried had that Document and Settings in the German
                        language as well.
                        >
                        However this is as well working here.
                        >
                        Environment.Spe cialFolder.MyPi ctures
                        >
                        I know that you knew this.
                        >
                        :-)
                        >
                        Cor
                        >
                        Therefore Environment.
                        "Tom Leylan" <tleylan@nospam .netschreef in bericht
                        news:Oo2qjefIHH A.4760@TK2MSFTN GP03.phx.gbl...
                        >I'd be shocked if that didn't work. It doesn't assign that string to the
                        >photoPath variable?
                        >>
                        >"DesCF" <descf@aol.comw rote in message
                        >news:op.tkplbp vrupgxg0@descst ar...
                        >The following doesn't work:
                        >>
                        >Dim photoPath As String = "R:\My Documents\My Pictures\MiscLL \"
                        >>
                        >It doesn't work if I use double quotes either. It does work if I use a
                        >different path without spaces in it. What is the simple solution ?
                        >>
                        >>
                        >>
                        >--
                        >Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
                        >>
                        >
                        >

                        Comment

                        • Tom Leylan

                          #13
                          Re: spaces in file paths

                          "When something doesn't seem to work correctly eliminate all the surrounding
                          code so you can concentrate on the one part that doesn't seem to work
                          correctly."

                          Did you try simply getting a directory and displaying the file names on your
                          local drive? If so did it work? I think you will find that it does work
                          whether or not there are spaces but you should confirm this. Now you know
                          that isn't the problem after all and you can spend some time finding real
                          problem.

                          BTW isn't your line: photos.Add(phot oPath + Path.GetFileNam e(photo)) the
                          same as simply using the photo value? Aren't you stripping the path off and
                          putting it back on?



                          "DesCF" <descf@aol.comw rote in message news:op.tkptcog qupgxg0@descsta r...
                          Right, the code for the entire web page is below.

                          If I create a directory J:\Fots and stick some photos in it, it works just
                          fine. If I change the directory name to J:\Fot s (i.e. insert a space
                          between the t and the s) it just displays the placeholders for the right
                          number of photos with little red X's in them.


                          <%@ Page Language="VB" %>
                          <%@ Import Namespace="Syst em.IO" %>
                          <%@ Import Namespace="Syst em.Collections. Generic" %>

                          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
                          "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
                          <script runat="server">

                          ''' <summary>
                          ''' Bind photos to Repeater
                          ''' </summary>
                          Sub Page_Load()
                          If Not Page.IsPostBack Then
                          Repeater1.DataS ource = GetPhotos()
                          Repeater1.DataB ind()
                          End If
                          End Sub

                          ''' <summary>
                          ''' Get list of photos from Photo folder
                          ''' </summary>
                          Public Function GetPhotos() As List(Of String)
                          Dim photos As New List(Of String)()
                          Dim photoPath As String = "J:\Fot s\"
                          Dim files As String() = Directory.GetFi les(photoPath)
                          For Each photo As String In files
                          photos.Add(phot oPath + Path.GetFileNam e(photo))
                          Next
                          Return photos
                          End Function

                          </script>
                          <html xmlns="http://www.w3.org/1999/xhtml" >
                          <head id="Head1" runat="server">
                          <title>Show Photos</title>
                          </head>
                          <body>
                          <form id="form1" runat="server">
                          <div>

                          <asp:Repeater
                          id="Repeater1"
                          runat="server">
                          <ItemTemplate >
                          <asp:Image
                          id="Image1"
                          Width="200px"
                          ImageUrl='<%# Container.DataI tem %>'
                          Runat="server" />
                          </ItemTemplate>
                          </asp:Repeater>

                          </div>
                          </form>
                          </body>
                          </html>



                          ---


                          On Sun, 17 Dec 2006 15:00:51 -0000, DesCF <descf@aol.comw rote:
                          The following doesn't work:
                          >
                          Dim photoPath As String = "R:\My Documents\My Pictures\MiscLL \"
                          >
                          It doesn't work if I use double quotes either. It does work if I use a
                          different path without spaces in it. What is the simple solution ?
                          >
                          >
                          >


                          --
                          Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


                          Comment

                          • Cor Ligthert [MVP]

                            #14
                            Re: spaces in file paths

                            Tom,

                            I agree with you, however I saw nowhere in the answers the message to the
                            Environment Special folder and thought as the OP has installed in a kind of
                            crazy way to that R folder while also writing it in an easy way, than this
                            could be the problem.

                            It can of course as well be incorrect rights on that virtual folder as it is
                            often.

                            :-)

                            Cor

                            "Tom Leylan" <tleylan@nospam .netschreef in bericht
                            news:uRWvishIHH A.780@TK2MSFTNG P03.phx.gbl...
                            Hi Cor:
                            >
                            I don't believe the assignment of either string would fail in any country
                            :-)
                            >
                            >
                            "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message
                            news:%23VGWiFhI HHA.1816@TK2MSF TNGP06.phx.gbl. ..
                            >Tom,
                            >>
                            >This is not in every country the same, here in Holland I have
                            >>
                            >C:\Documents and Settings\cor\Mi jn documenten\Mijn afbeeldingen
                            >>
                            >I thought that Herfried had that Document and Settings in the German
                            >language as well.
                            >>
                            >However this is as well working here.
                            >>
                            >Environment.Sp ecialFolder.MyP ictures
                            >>
                            >I know that you knew this.
                            >>
                            >:-)
                            >>
                            >Cor
                            >>
                            >Therefore Environment.
                            >"Tom Leylan" <tleylan@nospam .netschreef in bericht
                            >news:Oo2qjefIH HA.4760@TK2MSFT NGP03.phx.gbl.. .
                            >>I'd be shocked if that didn't work. It doesn't assign that string to
                            >>the photoPath variable?
                            >>>
                            >>"DesCF" <descf@aol.comw rote in message
                            >>news:op.tkplb pvrupgxg0@descs tar...
                            >>The following doesn't work:
                            >>>
                            >>Dim photoPath As String = "R:\My Documents\My Pictures\MiscLL \"
                            >>>
                            >>It doesn't work if I use double quotes either. It does work if I use a
                            >>different path without spaces in it. What is the simple solution ?
                            >>>
                            >>>
                            >>>
                            >>--
                            >>Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
                            >>>
                            >>
                            >>
                            >
                            >

                            Comment

                            • Cor Ligthert [MVP]

                              #15
                              Re: spaces in file paths

                              Tom,

                              Very good answer seen all others including mine

                              :-)

                              Cor

                              "Tom Leylan" <tleylan@nospam .netschreef in bericht
                              news:e$7pW2iIHH A.1912@TK2MSFTN GP03.phx.gbl...
                              "When something doesn't seem to work correctly eliminate all the
                              surrounding code so you can concentrate on the one part that doesn't seem
                              to work correctly."
                              >
                              Did you try simply getting a directory and displaying the file names on
                              your local drive? If so did it work? I think you will find that it does
                              work whether or not there are spaces but you should confirm this. Now you
                              know that isn't the problem after all and you can spend some time finding
                              real problem.
                              >
                              BTW isn't your line: photos.Add(phot oPath + Path.GetFileNam e(photo)) the
                              same as simply using the photo value? Aren't you stripping the path off
                              and putting it back on?
                              >
                              >
                              >
                              "DesCF" <descf@aol.comw rote in message
                              news:op.tkptcog qupgxg0@descsta r...
                              Right, the code for the entire web page is below.
                              >
                              If I create a directory J:\Fots and stick some photos in it, it works just
                              fine. If I change the directory name to J:\Fot s (i.e. insert a space
                              between the t and the s) it just displays the placeholders for the right
                              number of photos with little red X's in them.
                              >
                              >
                              <%@ Page Language="VB" %>
                              <%@ Import Namespace="Syst em.IO" %>
                              <%@ Import Namespace="Syst em.Collections. Generic" %>
                              >
                              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
                              "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
                              <script runat="server">
                              >
                              ''' <summary>
                              ''' Bind photos to Repeater
                              ''' </summary>
                              Sub Page_Load()
                              If Not Page.IsPostBack Then
                              Repeater1.DataS ource = GetPhotos()
                              Repeater1.DataB ind()
                              End If
                              End Sub
                              >
                              ''' <summary>
                              ''' Get list of photos from Photo folder
                              ''' </summary>
                              Public Function GetPhotos() As List(Of String)
                              Dim photos As New List(Of String)()
                              Dim photoPath As String = "J:\Fot s\"
                              Dim files As String() = Directory.GetFi les(photoPath)
                              For Each photo As String In files
                              photos.Add(phot oPath + Path.GetFileNam e(photo))
                              Next
                              Return photos
                              End Function
                              >
                              </script>
                              <html xmlns="http://www.w3.org/1999/xhtml" >
                              <head id="Head1" runat="server">
                              <title>Show Photos</title>
                              </head>
                              <body>
                              <form id="form1" runat="server">
                              <div>
                              >
                              <asp:Repeater
                              id="Repeater1"
                              runat="server">
                              <ItemTemplate >
                              <asp:Image
                              id="Image1"
                              Width="200px"
                              ImageUrl='<%# Container.DataI tem %>'
                              Runat="server" />
                              </ItemTemplate>
                              </asp:Repeater>
                              >
                              </div>
                              </form>
                              </body>
                              </html>
                              >
                              >
                              >
                              ---
                              >
                              >
                              On Sun, 17 Dec 2006 15:00:51 -0000, DesCF <descf@aol.comw rote:
                              >
                              >The following doesn't work:
                              >>
                              >Dim photoPath As String = "R:\My Documents\My Pictures\MiscLL \"
                              >>
                              >It doesn't work if I use double quotes either. It does work if I use a
                              >different path without spaces in it. What is the simple solution ?
                              >>
                              >>
                              >>
                              >
                              >
                              >
                              --
                              Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
                              >

                              Comment

                              Working...