Here is a curious one.
I have an ASP page which uses a search string to pull records from a database.
For a variety of reasons I then use a GetFileName function to cull the filename and extension, this is then used to populate a Javascript window.open routine to provide a link to the appropriate file.
It works fine - except for the first record retrieved on every search occasion which returns a null string instead of the filename.
The GetFileName function is this:
and the body of the ASP page opening the database and pulling the records is this:
(sorry, lots of added bits, have seperated lines to make clearer)
Can anyone fathom why the first returned entry in the table always returns a null string and hence an invalid link?
Cheers all.
I have an ASP page which uses a search string to pull records from a database.
For a variety of reasons I then use a GetFileName function to cull the filename and extension, this is then used to populate a Javascript window.open routine to provide a link to the appropriate file.
It works fine - except for the first record retrieved on every search occasion which returns a null string instead of the filename.
The GetFileName function is this:
Code:
<%
Function FileNameGet(strPath)
Dim fngFSO
set fngFSO = Server.CreateObject("Scripting.FileSystemObject")
nameoffile = fngFSO.getfilename(strPath)
Set fngFSO = Nothing
End Function
%>
and the body of the ASP page opening the database and pulling the records is this:
(sorry, lots of added bits, have seperated lines to make clearer)
Code:
rs.Open
If rs.RecordCount >= 1 then
Response.Write "<table cellpadding='5' border='0'><tr>"
Response.Write "<td style='color:black;text-decoration:underline'><strong><a class='sort' href='resort.asp?S=T&term=" & searchterm & "' title='Sort by title'>Title</a></strong></td>"
Response.Write "<td style='color:black;text-decoration:underline'><strong><a class='sort' href='resort.asp?S=C&term=" & searchterm & "' title='Sort by category'>Category</a></strong></td>"
Response.Write "<td style='color:black;text-decoration:underline'><strong><a class='sort' href='resort.asp?S=S&term=" & searchterm & "' title='Sort by subject'>Subject</a></strong></td>"
Response.Write "<td style='color:black;text-decoration:underline'><strong><a class='sort' href='resort.asp?S=A&term=" & searchterm & "' title='Sort by author'>Author</a></strong></td><td style='color:black;text-decoration:underline'><strong><a class='sort' href='resort.asp?S=J&term=" & searchterm & "' title='Sort by Journal'>Journal</a></strong></td>"
Response.Write "<td style='color:black;text-decoration:underline'><strong>File</strong></td>"
Response.Write "<td style='color:black;text-decoration:underline'><strong>Delete</strong></td>"
Response.Write "<td style='color:black;text-decoration:underline'><strong>Edit</strong></td></tr>"
Do Until rs.EOF
databasename=(rs("location"))
FileNameGet databasename
nametoopen="Files/" & nameoffile
Response.Write "<tr><td><a target='_blank' title='" & Replace(rs("comment"),"''","'") &"' href='" & nametoopen & "''" &">" & Replace(rs("title"),"''","'") & "</a></td>"
Response.Write "<td style='color:black'>" & Replace(rs("category"),"''","'") & "</td><td style='color:black'>" & Replace(rs("subject"),"''","'") & "</td>"
Response.Write "<td title='" & Replace(rs("forename"),"''","'") & " " & Replace(rs("surname"),"''","'") & "' style='color:black'>" & Replace(rs("surname"),"''","'") & "</td><td title='" & Replace(rs("journal"),"''","'") & ", " & Replace(rs("formalref"),"''","'") & "' style='color:black'>" & Replace(rs("publication"),"''","'") & "</td>"
Response.Write "<td style='text-transform:uppercase' style='color:black'>" & fileext & "</td>"
Response.Write "<td><a style='color:red' href='delete.asp?N=" & rs("ID") & "'>delete</a></td>"
Response.Write "<td><a style='color:blue' href='edit.asp?N=" & rs("ID") & "'>edit</a></td>"
Response.Write "<td><a href='#top'><img border='0' src='triangle.jpg' height='10' width='10' title='Back to top' /></a></td></tr>"
' added bits to display what the variables are if GetFileName is wrong
If nametoopen="Files/" then
Response.Write "<tr><td>database location=" & (databasename) & "</tr></td>"
Response.Write "<tr><td>Constructed target=" & nametoopen & "</td></tr>"
Response.Write "<tr><td>returned name from routine=" & nameoffile & "</td></tr>"
end if
rs.MoveNext
Loop
Response.Write "<tr><td><form method='post' action='print.asp' target='_blank'><input type='hidden' name='List' value='" & searchterm & "'><input type='submit' value='Print list' /></form></td></tr></table>"
Else
Session("badsearch")="true"
Response.redirect "search.asp"
End If
rs.Close
set rs = Nothing
Conn.close
set Conn = Nothing
%>
Can anyone fathom why the first returned entry in the table always returns a null string and hence an invalid link?
Cheers all.