views:

29

answers:

2

Hey,

anyone could help me understand the following asp.net 2.0 coding? It is supposed to show me a couple of the latest photos i uploaded to a particular folder in the photoalbum. however when i upload a new file in an folder which already has images... the images that show up when using the code is the first images in this folder... and sometimes nothing shows up...

<%
latestfolder = "na"
latestdate = cdate("01/01/09")

set fs=Server.CreateObject("Scripting.FileSystemObject")
set fo=fs.GetFolder(Server.MapPath("images/gallery"))

for each folder in fo.subfolders 
    if cdate(folder.DateLastModified) > latestdate then
        latestdate = cdate(folder.DateLastModified)
        latestfolder = folder.name
    end if
next

if latestfolder <> "na" then
    set fi=fs.GetFolder(Server.MapPath("images/gallery/" & latestfolder))
    looptimes = 0

    for each file in fi.files 
        if month(file.DateLastModified) = month(latestdate) then
            if right(lcase(file.Name),3) = "jpg" then %>
                <a href="thumbnail.aspx?picture=<%=server.URLEncode("images/gallery/" & latestfolder & "/" & file.Name)%>&maxWidth=640&maxHeight=480" target="_blank"  style="text-decoration:none; cursor:pointer;">
                    <img src="thumbnail.aspx?picture=<%=server.URLEncode("images/gallery/" & latestfolder & "/" & file.Name)%>&maxWidth=100&maxHeight=60" style="border:1px solid #ffffff; margin:5px; margin-top:14px;">
                </a>        
            <% end if 
        end if

        looptimes = looptimes + 1
        if looptimes = 6 then exit for end if

    next

end if
%>

hope some can help me :)

+1  A: 

Looks like the following code is picking up all JPEG files for the current month:

if month(file.DateLastModified) = month(latestdate) then
    if right(lcase(file.Name),3) = "jpg" then%>
        ...
    <% end if
end if
artdanil
A: 

when it loops through the files, it checks whether the last modified date of the image matches the last modified date of the folder. that is the original coders definition of "a couple of the latest photos" for that album. it also makes sure that there's never more than 6.

If you don't upload photos all too often, you could easily end up with just one photo every time. If you don't get any photos out of it at all, you've probably done something else in that folder, that would've changed its last modified date, without adding any photos.

I'd consider getting rid of the month criteria, and just stick with the 6 photos limit, i.e. replace

    if month(file.DateLastModified) = month(latestdate) then
        if right(lcase(file.Name),3) = "jpg" then %>
            <a href="thumbnail.aspx?picture=<%=server.URLEncode("images/gallery/" & latestfolder & "/" & file.Name)%>&maxWidth=640&maxHeight=480" target="_blank"  style="text-decoration:none; cursor:pointer;">
                <img src="thumbnail.aspx?picture=<%=server.URLEncode("images/gallery/" & latestfolder & "/" & file.Name)%>&maxWidth=100&maxHeight=60" style="border:1px solid #ffffff; margin:5px; margin-top:14px;">
            </a>        
        <% end if 
    end if

with

    if right(lcase(file.Name),3) = "jpg" then %>
        <a href="thumbnail.aspx?picture=<%=server.URLEncode("images/gallery/" & latestfolder & "/" & file.Name)%>&maxWidth=640&maxHeight=480" target="_blank"  style="text-decoration:none; cursor:pointer;">
            <img src="thumbnail.aspx?picture=<%=server.URLEncode("images/gallery/" & latestfolder & "/" & file.Name)%>&maxWidth=100&maxHeight=60" style="border:1px solid #ffffff; margin:5px; margin-top:14px;">
        </a>        
    <% end if
David Hedlund
david, thanks for your answers... could you please tell me which in your opinion i should delete like tell me the exact coding... as im not so great in coding.. a friend of mine had coded that for me... and i cannot fully understand it.
Josmar Azzopardi
no worries, see my edit
David Hedlund
hey david,now the images showed up,BUT still the images which are first in the photoalbum show up.not the latest photos i uploaded.you can see where the above script ishttp://xaghrascouts.com/default.aspand these are the latest photos i uploaded (which are at the bottom)http://xaghrascouts.com/album.asp?cat=JAkKGFdIQjIcABADC0VWQ0RWthanks a lot if you can help me :)
Josmar Azzopardi
any more help if you can :/
Josmar Azzopardi