VBdotnet2005
asked on
Gridview - filenames
I have this code under Page load. How can I add filenames and create a hyperlink in table ?
Const IMAGE_DIRECTORY As String = "myimages/"
Dim s, html As String
Dim sb As New StringBuilder()
For Each s In Directory.GetFiles(Server. MapPath(IM AGE_DIRECT ORY), "*.jpg")
html = "<img src=""" & IMAGE_DIRECTORY & Path.GetFileName(s) & """ width=""520"" height=""400"">"
sb.Append(" " & html)
Next
litImages.Text = sb.ToString
End Sub
Const IMAGE_DIRECTORY As String = "myimages/"
Dim s, html As String
Dim sb As New StringBuilder()
For Each s In Directory.GetFiles(Server.
html = "<img src=""" & IMAGE_DIRECTORY & Path.GetFileName(s) & """ width=""520"" height=""400"">"
sb.Append(" " & html)
Next
litImages.Text = sb.ToString
End Sub
Here you go:
Const IMAGE_DIRECTORY As String = "myimages/"
Dim s, html As String
Dim sb As New StringBuilder
html = "<TABLE id=Table1 cellSpacing=1 cellPadding=1 width=300 border=1>"
For Each s In Directory.GetFiles(Server. MapPath(IM AGE_DIRECT ORY), "*.jpg")
html = html & "<TR>"
html = html & "<TD><img src="" & IMAGE_DIRECTORY & Path.GetFileName(s) & "" width=520 height=400></TD>"
html = html & "<TD><a href="" & IMAGE_DIRECTORY & Path.GetFileName(s) & "">" & IMAGE_DIRECTORY & Path.GetFileName(s) & "</a></TD>"
html = html & "</TR>"
Next
html = html & "</TABLE>"
litImages.Text = sb.ToString
>>> Here you can use this html string to display in any other control.
Const IMAGE_DIRECTORY As String = "myimages/"
Dim s, html As String
Dim sb As New StringBuilder
html = "<TABLE id=Table1 cellSpacing=1 cellPadding=1 width=300 border=1>"
For Each s In Directory.GetFiles(Server.
html = html & "<TR>"
html = html & "<TD><img src="" & IMAGE_DIRECTORY & Path.GetFileName(s) & "" width=520 height=400></TD>"
html = html & "<TD><a href="" & IMAGE_DIRECTORY & Path.GetFileName(s) & "">" & IMAGE_DIRECTORY & Path.GetFileName(s) & "</a></TD>"
html = html & "</TR>"
Next
html = html & "</TABLE>"
litImages.Text = sb.ToString
>>> Here you can use this html string to display in any other control.
ASKER
It does not display any images
Const IMAGE_DIRECTORY As String = "myimages/"
Dim s, html As String
Dim sb As New StringBuilder
html = "<TABLE id=Table1 cellSpacing=1 cellPadding=1 width=300 border=1>"
For Each s In Directory.GetFiles(Server. MapPath(IM AGE_DIRECT ORY), "*.jpg")
html = html & "<TR>"
html = html & "<TD><img src="" & IMAGE_DIRECTORY & Path.GetFileName(s) & "" width=520 height=400></TD>"
html = html & "<TD><a href="" & IMAGE_DIRECTORY & Path.GetFileName(s) & "">" & IMAGE_DIRECTORY & Path.GetFileName(s) & "</a></TD>"
html = html & "</TR>"
Next
html = html & "</TABLE>"
litImages.Text = sb.ToString
End Sub
Const IMAGE_DIRECTORY As String = "myimages/"
Dim s, html As String
Dim sb As New StringBuilder
html = "<TABLE id=Table1 cellSpacing=1 cellPadding=1 width=300 border=1>"
For Each s In Directory.GetFiles(Server.
html = html & "<TR>"
html = html & "<TD><img src="" & IMAGE_DIRECTORY & Path.GetFileName(s) & "" width=520 height=400></TD>"
html = html & "<TD><a href="" & IMAGE_DIRECTORY & Path.GetFileName(s) & "">" & IMAGE_DIRECTORY & Path.GetFileName(s) & "</a></TD>"
html = html & "</TR>"
Next
html = html & "</TABLE>"
litImages.Text = sb.ToString
End Sub
ASKER
Code below display images almost the same as mine. That does not answer my question at all.
Const IMAGE_DIRECTORY As String = "images/"
Dim s As String
Dim html As New HtmlGenericControl
Dim sb As New StringBuilder()
For Each s In Directory.GetFiles(Server. MapPath(IM AGE_DIRECT ORY), "*.jpg")
html.InnerHtml &= "<img src=""" & IMAGE_DIRECTORY & Path.GetFileName(s) & """ width=""520"" height=""400"">" 'here u can use any html u want to place....
Next
place.Controls.Add(html)
and in design page u have to give <td> a id so u can place content of htmlgenericcontrol to this <td>
<table>
<tr>
<td id ="place" runat="server">
</td>
</tr>
</table>
Const IMAGE_DIRECTORY As String = "images/"
Dim s As String
Dim html As New HtmlGenericControl
Dim sb As New StringBuilder()
For Each s In Directory.GetFiles(Server.
html.InnerHtml &= "<img src=""" & IMAGE_DIRECTORY & Path.GetFileName(s) & """ width=""520"" height=""400"">" 'here u can use any html u want to place....
Next
place.Controls.Add(html)
and in design page u have to give <td> a id so u can place content of htmlgenericcontrol to this <td>
<table>
<tr>
<td id ="place" runat="server">
</td>
</tr>
</table>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Const IMAGE_DIRECTORY As String = "images/"
Dim s As String
Dim html As New HtmlGenericControl
Dim sb As New StringBuilder()
For Each s In Directory.GetFiles(Server.
html.InnerHtml &= "<img src=""" & IMAGE_DIRECTORY & Path.GetFileName(s) & """ width=""520"" height=""400"">" 'here u can use any html u want to place....
Next
place.Controls.Add(html)
and in design page u have to give <td> a id so u can place content of htmlgenericcontrol to this <td>
<table>
<tr>
<td id ="place" runat="server">
</td>
</tr>
</table>