Home All Groups Group Topic Archive Search About

Datalist - Image loads on localhost but not on server

Author
9 May 2005 6:28 PM
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

Author
10 May 2005 3:07 AM
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?

Show quoteHide quote
"Angie" <angela***@comcast.net> wrote in message
news:1115663313.915209.164990@f14g2000cwb.googlegroups.com...
>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
>
Author
10 May 2005 5:10 AM
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!
Author
10 May 2005 12:09 PM
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


Show quoteHide quote
"Angie" <angela***@comcast.net> wrote in message
news:1115701813.869172.247160@f14g2000cwb.googlegroups.com...
> 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!
>
Author
10 May 2005 4:29 PM
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
Author
10 May 2005 6:51 PM
vMike
"Angie" <angela***@comcast.net> wrote in message
news:1115742564.585903.165740@o13g2000cwo.googlegroups.com...
Ken,

I have tried working backwards with:
Dim albumPath As String = "./images/album­s/" +



remove the . in front of the /
Author
11 May 2005 12:12 AM
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
Author
11 May 2005 2:05 PM
vMike
"Angie" <angela***@comcast.net> wrote in message
news:1115770364.278007.229950@f14g2000cwb.googlegroups.com...
> 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
I don't think it is anything to do with your isp.

The src tag of the your images is, for example

src="e:\html\domains\marinehillspool.org\wwwroot\images\Albums\Workparties\I
MG_0057001.jpg"

It should be src="/images/Albums/Workparties/IMG_0057001.jpg".

Check you code. You should not be adding the entire file path to the src
tag.

Try creating a simple file as follows.

<html>
<body>
<img src="/images/Albums/Workparties/IMG_0057001.jpg" />
</body>
</html>

and try it on you isp. I think you will find that it works fine. You code
needs to produce the same src tag.

Mike
Author
11 May 2005 2:11 PM
vMike
"vMike" <Michael.George@spamnotgewarren.com.delete> wrote in message
news:gioge.942$wM2.53@newsread1.news.atl.earthlink.net...
>
> "Angie" <angela***@comcast.net> wrote in message
> news:1115770364.278007.229950@f14g2000cwb.googlegroups.com...
> > vMike,

To show to you that it does work. the image numbered IMG_0057001.jpg  has a
lawnmower in the front with a bunch of grill in the back with two people.
There is also a man standing in the front with gloves. I had to add the full
url to test but you would not want to do that in your code as follows.

<html>
<body>
<img
src="http://www.marinehillspool.org/images/Albums/Workparties/IMG_0057001.jp
g" />
</body>
</html

Mike
Author
12 May 2005 3:21 AM
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
Author
12 May 2005 2:15 PM
vMike
"Angie" <angela***@comcast.net> wrote in message
news:1115868061.580834.63470@o13g2000cwo.googlegroups.com...
> 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.
>
You don't need to bind the pictures to the datalist, you need to bind the
string that points to the picture in the datalist.
Author
12 May 2005 4:58 PM
Angie
Can you please show me how to do that?
Author
12 May 2005 6:06 PM
vMike
"Angie" <angela***@comcast.net> wrote in message
news:1115917135.230966.299040@g44g2000cwa.googlegroups.com...
> Can you please show me how to do that?
>
In this bit of code

For Each file As String In Directory.GetFiles(albumPath)
Select Case Path.GetExtension(file).ToLower
Case ".gif", ".bmp", ".jpg", ".jpeg"
arrPictures.Add(file)


change arrPictures.Add(file) to
arrPictures.Add(file.substring(file.indexof("marinehillspool.org") + 19))
Author
12 May 2005 6:09 PM
vMike
Show quote Hide quote
"vMike" <Michael.George@spamnotgewarren.com.delete> wrote in message
news:1XMge.1365$bm5.798@newsread3.news.atl.earthlink.net...
>
> "Angie" <angela***@comcast.net> wrote in message
> news:1115917135.230966.299040@g44g2000cwa.googlegroups.com...
> > Can you please show me how to do that?
> >
> In this bit of code
>
> For Each file As String In Directory.GetFiles(albumPath)
> Select Case Path.GetExtension(file).ToLower
> Case ".gif", ".bmp", ".jpg", ".jpeg"
> arrPictures.Add(file)
>
>
> change arrPictures.Add(file) to
> arrPictures.Add(file.substring(file.indexof("marinehillspool.org") + 19))
>
Actually the + 19 should be + 26 sorry.
Author
12 May 2005 6:36 PM
vMike
"vMike" <Michael.George@spamnotgewarren.com.delete> wrote in message
news:4ZMge.1366$bm5.515@newsread3.news.atl.earthlink.net...
>
> "vMike" <Michael.George@spamnotgewarren.com.delete> wrote in message
> news:1XMge.1365$bm5.798@newsread3.news.atl.earthlink.net...
> >
> > "Angie" <angela***@comcast.net> wrote in message
> > news:1115917135.230966.299040@g44g2000cwa.googlegroups.com...
> > > Can you please show me how to do that?
> > >
A better approach might be something like this


dim arr as string() = Directory.GetFiles(albumPath)
Dim i as int32
  for i = 0 to arr.getupperbound(0)
     dim fi as new fileinfo(Arr(i))
     dim filename as string = fi.name
     Select case fi.extention.tolower
    case is ".gif", ".bmp", ".jpg", ".jpeg"

     arrPictures.Add("/images/Albums/Workparties/" + fi.name)
   end select
next i