Datalist - Image loads on localhost but not on server

A

Angie

I have a datalist that displays images from a folder. It works on my
local host but I just get the boxed red x online. Right below the image
is the file name and that is displaying correctly both locally and
online. I called my host to make sure permissions were okay - they said
yes. When I right click the red x it is pointing to the right folder?

Thank you in advance.
Angie

Code listed below:

Function LoadPictures(ByVal PictureFolder As String)

Dim albumPath As String = Server.MapPath("./images\albums\" +
PictureFolder)
Dim arrPictures As New ArrayList
'open and shut panels accordingly
pnlAlbum.Visible = False
pnlPictures.Visible = True

For Each file As String In Directory.GetFiles(albumPath)
Select Case Path.GetExtension(file).ToLower
Case ".gif", ".bmp", ".jpg", ".jpeg"
arrPictures.Add(file)
End Select
Next
With dgPictures
..DataSource = arrPictures
..DataBind()
If dgPictures.Items.Count > 0 Then
lblAlbums.Text = "If you are interested in getting a copy of a picture,
please email the web site."
Else
lblAlbums.Text = "There was an error loading pictures."
Response.Redirect("pictures.aspx")
End If
End With
End Function
 
K

Ken Cox [Microsoft MVP]

Hi Angie,

A couple things to check...

When you look at the rendered HTML for the image, is it correct? If you
paste that URL into a new browser instance, do you get the image?

Are there any unusual characters or spaces in the image filename?

Is it possible that a bad version is caught in a cache?

Is the Web set as an Application on the server machine?
 
A

Angie

Ken,

I hope I understand what your saying; if I right click and look at the
properties on the image it shows
file:///e:/html/domains/mywebsite.org/wwwroot/Images/Albums/Workparties/IMG_0057001.jpg.
If I paste the URL into a new browser no I don't get the image. When I
run it on my localhost and it displays correctly the properties show:
file:///C:/Inetpub/wwwroot/mywebsite/Images/Albums/Workparties/IMG_0057001.jpg
- if I copy that into the browser it opens my picture editor. If I put
a regular image on the page and type
"./Images/Albums/Workparties/IMG_0057001.jpg" it displays correctly
online and localhost.

I am new to asp.net so I haven't done anything with cache? I have had
other people try it on their computer and we are all having the same
results.

The web site is set as an application.

The example I was using in the book was getting the images from the c:
drive and I'm wondering if that is the problem.
I don't know enough about this to know where to look - I have searched
and searched for examples and am not coming up with them.

Thank you!
 
K

Ken Cox [Microsoft MVP]

Hi Angie,

There's a serious problem with the URL. It is referencing the file system on
your computer rather than the Web server virtual directory.

The paths you're showing don't make any sense to the browser.

I think you're being misled by the code in the book. It may be for another
purpose, not sure.

Ken
 
A

Angie

Ken,

I have tried working backwards with:
Dim albumPath As String = "./images/album­s/" +
PictureFolder
The error message there was that it was missing part of the path and
wouldn't load online or localhost.

I have also tried Server.Mappath, Me.Mappath and Page.Mappath all of
them are loading locally but not online - all of them still have the
URL from above.

I also tried moving the pictures to a folder at the same level of the
bin but that again worked locally but not online.

So if I have a serious problem with my URL what do I do. Am I heading
down the wrong road OR should this work and it is something wrong
somewhere else.

This is an established website and all the other pages are working
great. I have worked quite a bit with database connections and having
data and pictures display from there BUT this is the first time I
wanted the pictures to come out of a folder, into an arraylist and
display from there based on what "event" it was.

Here is my code from the datalist (not sure if that will help or not).
As I said before the file name (below the picture) is showing correctly
so I'm assuming that they are loading into the arraylist correctly it's
just a matter of them not displaying (red x):
<ItemTemplate>
<asp:Image ID="imgPicure" width="180px" ImageUrl='<%#Container.DataItem
%>' Runat="server"></asp:Image>
<asp:label ID="lblPicture" Runat="server"
Text='<%#System.IO.Path.GetFileName(Container.DataItem)
%>'></asp:label>
</ItemTemplate>

Again, thank you for any help!
Angie
 
A

Angie

vMike,

I wish life was that easy. I have tried every combination known to man
but I come up with the same error OR it has no error but won't display
the image. I have my isp checking their side of things. I just backed
up my work today and am thinking of reinstalling VisualStudio - maybe
somewhere something got out of whack!

If you want to see what shows up on the page go to
http://www.marinehillspool.org/pictures.aspx | click on Work Party in
the middle and you will see what is happening. Notice the file name
right below where the picture should be...it's coming out of the same
arraylist as the pictures?

I'm either one step away from it working or I'm way off - not sure but
every example I look at does it this way.

Thank you - I do appreciate the suggestions!
Angie
 
A

Angie

Mike,

If I put a image on the page and type the src as "/images/" +
PictureFolder +"/IMG_0057001.jpg" it works great. But I need to get the
pictures out of a folder (on the server
/images/Albums/{PictureFolder}), put them in an arraylist and bind them
to a datalist.

The example I had used was getting them from the harddrive of c: with
Server.Mappath - I assumed, incorrectly it seems, that it would adjust
for the virtual path of a web site. It doesn't it points to the
absolute path which is why the e:..... is showing up.

I'm looking at another example right now from 4guysfromrolla.com - it's
dealing with server.mappath also but slightly different. I really
haven't found a good example of how to do it yet...any good examples or
ideas?

I appreciate your help.

Thanks Angie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top