Datalist - Image loads on localhost but not on server

Discussion in 'ASP .Net Web Controls' started by Angie, May 9, 2005.

  1. Angie

    Angie Guest

    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
     
    Angie, May 9, 2005
    #1
    1. Advertising

  2. 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?

    "Angie" <> wrote in message
    news:...
    >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
    >
     
    Ken Cox [Microsoft MVP], May 10, 2005
    #2
    1. Advertising

  3. Angie

    Angie Guest

    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!
     
    Angie, May 10, 2005
    #3
  4. 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


    "Angie" <> wrote in message
    news:...
    > 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!
    >
     
    Ken Cox [Microsoft MVP], May 10, 2005
    #4
  5. Angie

    Angie Guest

    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
     
    Angie, May 10, 2005
    #5
  6. Angie

    Angie Guest

    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
     
    Angie, May 11, 2005
    #6
  7. Angie

    Angie Guest

    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
     
    Angie, May 12, 2005
    #7
  8. Angie

    Angie Guest

    Can you please show me how to do that?
     
    Angie, May 12, 2005
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jiong Feng
    Replies:
    0
    Views:
    837
    Jiong Feng
    Nov 19, 2003
  2. Haydnw
    Replies:
    5
    Views:
    469
    =?Utf-8?B?amdyYW50?=
    Sep 25, 2004
  3. Alex
    Replies:
    4
    Views:
    572
    Hasani Blackwell
    Feb 8, 2005
  4. =?Utf-8?B?S2VuTGVl?=
    Replies:
    5
    Views:
    2,716
  5. koicat
    Replies:
    0
    Views:
    228
    koicat
    Jul 2, 2010
Loading...

Share This Page