Solved

Gridview - filenames

Posted on 2006-11-18
5
241 Views
Last Modified: 2011-09-20
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(IMAGE_DIRECTORY), "*.jpg")

            html = "<img src=""" & IMAGE_DIRECTORY & Path.GetFileName(s) & """ width=""520"" height=""400"">"
            sb.Append("&nbsp;&nbsp;" & html)

        Next

        litImages.Text = sb.ToString
 
End Sub
0
Comment
Question by:VBdotnet2005
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:badalpatel
ID: 17977344
u can use the htmlgeneric control..

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(IMAGE_DIRECTORY), "*.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>
0
 
LVL 12

Expert Comment

by:sandip132
ID: 17977521
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(IMAGE_DIRECTORY), "*.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.
0
 

Author Comment

by:VBdotnet2005
ID: 18001085
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(IMAGE_DIRECTORY), "*.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
0
 

Author Comment

by:VBdotnet2005
ID: 18001095
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(IMAGE_DIRECTORY), "*.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>
0
 
LVL 6

Accepted Solution

by:
badalpatel earned 500 total points
ID: 18001117
try this code
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(IMAGE_DIRECTORY), "*.jpg")
            html.InnerHtml &= "<TABLE id=Table1 cellSpacing=1 cellPadding=1 width=300 border=1><TR>"
            html.InnerHtml &= "<TD><img src=""" & IMAGE_DIRECTORY & Path.GetFileName(s) & """ width=""520"" height=""400""></TD>"     'here u can use any html u want to place....
           html.InnerHtml &="<TD><a href="" & IMAGE_DIRECTORY & Path.GetFileName(s) & "">" & IMAGE_DIRECTORY & Path.GetFileName(s) & "</a></TD></tr></table>"

        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>
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now