"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>