1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

how to display images using files form web server?

Discussion in 'C#' started by akinak, Jun 4, 2008.

  1. #1
    Iam trying to build a simple image gallery,that displays image form the files on web server and displays it on webpage.

    I tried, but my code displays some random text instead of an image. Here is the code:

    <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <% dim objFSO,objFolder,objFile,objOpen
    Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
    Set objFolder=objFSO.GetFolder(Server.MapPath("hall"))
    for Each objFile in objFolder.Files
    Set objOpen=objFile.OpenAsTextStream(1)
     do while Not objOpen.AtEndOfStream
      Response.Write objOpen.ReadAll
     Loop  
     objOpen.Close
     Response.Write "<br>"
    Next
    Set objOpen=nothing
    Set objFolder=nothing
    Set objFSO=nothing
    %>
    </body>
    </html>
    
    Code (markup):
    What is happening? How can I display the image from a file?
    Plz help..
     
    akinak, Jun 4, 2008 IP
  2. tacosalad

    tacosalad Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this

    <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
    <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <% dim objFSO,objFolder,objFile,objOpen
    Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
    Set objFolder=objFSO.GetFolder(Server.MapPath("hall"))
    for Each objFile in objFolder.Files
    
      Response.Write "<img src=hall/"& objFile.Name & ">"
    
     Response.Write "<br>"
    Next
    Set objOpen=nothing
    Set objFolder=nothing
    Set objFSO=nothing
    %>
    </body>
    </html>
    Code (markup):
     
    tacosalad, Jun 4, 2008 IP
  3. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thnx for replying. I tried but it gives an error:

    What does this mean now? What should I do to resolve it?
     
    akinak, Jun 4, 2008 IP
  4. Link.ezer.com

    Link.ezer.com Peon

    Messages:
    647
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    0
    #4
    perhaps there are too many files in that folder
    or many files are not image files and those files keep running.
     
    Link.ezer.com, Jun 5, 2008 IP
  5. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    there r five images in that folder and all are compressed. but when I view the properties of that folder, it shows there r 6 files. I don't see the sixth file..not even when I opted to view the hidden files. I don't knw from where it came. But yes when I was trying to find out the sixth file I saw somewhere its a DB file..but how to access that file? And I never put a DB file..so from where did it came? nyways..now the question is how to acces that file and delete it from there?
     
    akinak, Jun 5, 2008 IP
  6. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I found the DB file. IIS shows a thumbs.db file. which file is it? Iam not able to access the file. Can I delete it?
     
    akinak, Jun 5, 2008 IP
  7. BlogSalesman

    BlogSalesman Well-Known Member

    Messages:
    1,687
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    100
    #7
    Yes, you can deleted it.

    Can you ASP.Net instead? I have a script I use to do this written in .Net in about 3 lines.
     
    BlogSalesman, Jun 5, 2008 IP
  8. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    thnx. I deleted the file. I also searched on the net and selected not to cache the thumb images. But still I have the same error message.

    blogsalesman, thnx so much but I would like to do it in ASP( Iam a newbie and trying to learn). Can you plz help me with that?
     
    akinak, Jun 5, 2008 IP
  9. BlogSalesman

    BlogSalesman Well-Known Member

    Messages:
    1,687
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    100
    #9
    If you are a noob, why are you trying to learn an (almost) dead language?
     
    BlogSalesman, Jun 5, 2008 IP
  10. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    .net is next on my list to learn. I thought its better to know ASP before I go further with .net.
     
    akinak, Jun 5, 2008 IP
  11. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    btw can you tell me a good book for asp.net. I would like to start with it. n yeah can you also give me the script that you have to resolve my problem?
     
    akinak, Jun 5, 2008 IP
  12. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    any help to solve my problem? I cannot figure out..plz help
     
    akinak, Jun 5, 2008 IP
  13. Link.ezer.com

    Link.ezer.com Peon

    Messages:
    647
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    0
    #13
    you may try

    if right(objFile,4)=".jpg" or right(objFile,4)=".gif" then
    Response.Write " : <img src=http://domain_com/image_file/"& objFile.Name & ">"
    end if

    an example code info at http://3w.ezer.com/asp/file/server.mappath.asp
     
    Link.ezer.com, Jun 5, 2008 IP
  14. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I tried but still have the same error. Its not working :(. what to do?
     
    akinak, Jun 6, 2008 IP
  15. Link.ezer.com

    Link.ezer.com Peon

    Messages:
    647
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    0
    #15
    works fine here.

    as the example code showing
    you may narrow down images from countI<100 to countI<10 or countI<2

    and recheck your mappath and <img src=http://self_domain_com/image_folder/"& objFile.Name & ">"

    use self_domain_com same as it belongs , do not use other domains
     
    Link.ezer.com, Jun 6, 2008 IP
  16. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Link.ezer - It worked..thnx. I was making a mistake in adding the code you gave.
     
    akinak, Jun 9, 2008 IP