FTP Filename download then display images

Posted by Hywel.Roberts under ASP.NET on 11/18/2008 | Views : 2864 | Status : [Member] | Replies : 2
Have succesfully downloaded a variable number of .jpg image filenames into a variable dimension array. Can print these out as text successfully so can verify data is sound.

How do I use the array [RawFileNames()] as a valid entry in an <img src= ??????? alt="Anything" title="Anything" />

As you will see from the sample code which follows I am no professional, just a guy who wants to produce a simple solution to a personal project :-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<title>FTCW</title>
'<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>

<body bgcolor="#FFFFAA">
<%

Dim RawFileNames()
Dim RawFileCount

set ftp = Server.CreateObject("Chilkat.Ftp2")

success = ftp.UnlockComponent("Any Code")
If (success <> 1) Then
Response.write ftp.LastErrorText & "<br>"
End If

ftp.Hostname = "*************"
ftp.Username = "*************"
ftp.Password = "*************"

' Connect and login to the FTP server.
success = ftp.Connect()
If (success <> 1) Then
Response.write ftp.LastErrorText & "<br>"
End if

' Change to Data Directory
success = ftp.ChangeRemoteDir("/public_html/RawData")
If (success <> 1) Then
Response.write ftp.LastErrorText & "<br>"
End If

' Just get the active .jpg files - no directories
ftp.ListPattern = "*.jpg"

' How many files have we got?
n = ftp.NumFilesAndDirs
If (n < 0) Then
Response.write "Error - *** " & ftp.LastErrorText & "<br>"
End If

' Redimension the array to take all file names and
' then store all the file names in the array
Redim RawFileNames(n+1)

If (n > 0) Then
For i = 0 To n - 1
RawFileNames(i) = ftp.GetFilename(i)
Next
End If

%>

' Display first two images together with their titles doctored from the file name.
<div id="container">
<ul>
<li>
<% imagename = "images/" & RawFileNames(0)

Response.Write "<img src= imagename alt=""Photo One"" title=""1st Picture"" width=""110"" height=""60""/> "
Response.Write "<br>"

myString = RawFileNames(0)
PictureDate = Mid(myString,InStr(MyString,"_")+7,2) & "/" & Mid(myString,InStr(MyString,"_")+5,2) & "/" & Mid(myString,InStr(MyString,"_")+1,4)
'"<br>"
Response.write WeekDayName(WeekDay(picturedate)) & " - " & DatePart("d",PictureDate) & " " & MonthName(DatePart("m", PictureDate)) & " " & DatePart("yyyy",PictureDate) '& " at "
Response.Write " at " & Mid(myString,InStr(MyString,"_")+9,2) & ":" & Mid(myString,InStr(MyString,"_")+11,2)
Response.Write " " & "<br>"
%>
<br>
</li>
<li>
<img src= "images" & RawFileNames(1) alt="Photo Two" title="2nd Picture" width="110" height="60" />
<br>
<%
myString = RawFileNames(1)
PictureDate = Mid(myString,InS




Responses

Posted by: Raja on: 11/18/2008 [Member] Starter

Up
0
Down
You can loop through the array RawFileNames() and build the image <img src= ??????? alt="Anything" title="Anything" /> string and write on the page.

eg.

StringBuilder strB = new StringBuilder("");

for (int j=0;j<RawFileNames.Length;j++)
{
strB.Append("<img src=\""+ RawFileNames[j] + "\" title=\"Anything\" alt=\"Anything\" />");
}
Response.Write(strB.ToString());


Hope this will give some idea.

Thanks

Regards,
Raja, USA

Hywel.Roberts, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hywel.roberts on: 11/19/2008 [Member] Starter

Up
0
Down
Thanks Raja

The problem is not the creation of the string althought your use of stringbuilder has opened up a whole new learning experience for me.

put simply, this works

<img src= "abcde.jpg" alt="Photo Two" title="2nd Picture" />

but this doesn't

strfilename = "abcde.jpg"
<img src= strfilename alt="Photo Two" title="2nd Picture" />

Why not, and how do I get round it.

Hywel.Roberts, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response