spaces in file paths

  • Thread starter Thread starter DesCF
  • Start date Start date
D

DesCF

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 ?
 
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)
http://emoreau.s2i.com/

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 ?
 
I'd be shocked if that didn't work. It doesn't assign that string to the
photoPath variable?

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 ?
 
DesCF said:
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?!
 
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="System.IO" %>
<%@ Import Namespace="System.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.DataSource = GetPhotos()
Repeater1.DataBind()
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.GetFiles(photoPath)
For Each photo As String In files
photos.Add(photoPath + Path.GetFileName(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.DataItem %>'
Runat="server" />
</ItemTemplate>
</asp:Repeater>

</div>
</form>
</body>
</html>
 
I tried this and I get an invalid characters in path error. Thanks for
the suggestion anyrate.
 
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.
 
Tom,

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

C:\Documents and Settings\cor\Mijn 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.SpecialFolder.MyPictures

I know that you knew this.

:-)

Cor

Therefore Environment.
 
Des

if it is your own map, than it is mostly

Environment.SpecialFolder.MyPictures

Cor

"DesCF" <[email protected]> schreef in bericht
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 ?
 
Cor,

Cor Ligthert said:
This is not in every country the same, here in Holland I have

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

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

It's "C:\Dokumente und Einstellungen\...\Eigene Dokumente\Eigene Bilder" on
my German version of Windows XP.
 
Hi Cor:

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


Cor Ligthert said:
Tom,

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

C:\Documents and Settings\cor\Mijn 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.SpecialFolder.MyPictures

I know that you knew this.

:-)

Cor

Therefore Environment.
 
"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(photoPath + Path.GetFileName(photo)) the
same as simply using the photo value? Aren't you stripping the path off and
putting it back on?



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="System.IO" %>
<%@ Import Namespace="System.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.DataSource = GetPhotos()
Repeater1.DataBind()
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.GetFiles(photoPath)
For Each photo As String In files
photos.Add(photoPath + Path.GetFileName(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.DataItem %>'
Runat="server" />
</ItemTemplate>
</asp:Repeater>

</div>
</form>
</body>
</html>
 
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 said:
Hi Cor:

I don't believe the assignment of either string would fail in any country
:-)
 
DesCF said:
Right, the code for the entire web page is below.

Ahhhh, web page... URLs... no unencoded spaces allowed.
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.

If you want a space in a URL, change it to "%20" or "+" for the browser. See
the UrlEncode function. A better option would be to not use spaces. Look at
the generated URLs in the resultant web page and see what the browser is
trying to ask for and also remember to look in the web server's logfile to
see what was requested and why it could not be returned.

Does that make sense?

Andrew
 
I have tried inserting %20 and + and I get back 'Could not find a part of
the path 'J:\Fot%20s'.' and 'Could not find a part of the path
'J:\Fot+s'.' respectively. I cannot find the UrlEncode function.

The URL Address of an empty picture placeholder is:
file:///J:/Fot%2520s/0001.jpg

I do not know where to find the web servers log file. I am using Visual
Web Developer and it creates a kind of pop-up web server on the fly.
 
DesCF said:
I have tried inserting %20 and + and I get back 'Could not find a
part of the path 'J:\Fot%20s'.' and 'Could not find a part of the path
'J:\Fot+s'.' respectively.

Which program do those error messages come from?
I cannot find the UrlEncode function.

Are you saying that VWD comes without searchable help?
System.Web.HttpServerUtility.UrlEncode
The URL Address of an empty picture placeholder is:
file:///J:/Fot%2520s/0001.jpg

Is that when looking at the source in a browser? Because %25 is the encoding
for "%", so it looks like the URL encoding might have been done for you
already.
I do not know where to find the web servers log file. I am using
Visual Web Developer and it creates a kind of pop-up web server on
the fly.

I see from the info about VWD that "Visual Web Developer includes the
ability to create your Web applications using a Web server, FTP site, or
file share. File share-based Web sites are great for testing and don't
require you to have IIS installed on your computer, making them a great
solution on Windows XP Home Edition users." (source:
http://msdn.microsoft.com/vstudio/express/vwd/features/deploy/default.aspx ).

Apparently you have found a case where file share-based web sites are /not/
great for testing. Could you install IIS and use that, or are you on XP
Home?

Also, you could use FileMon
(http://www.microsoft.com/technet/sysinternals/utilities/filemon.mspx) or
its successor ProcessMonitor
(http://www.microsoft.com/technet/sysinternals/processesandthreads/processmonitor.mspx)
to see what file the browser is requesting.

Or maybe you could just use paths and filenames without spaces?

Andrew
 
Back
Top