Help directoryinfo/fileinfo

Posted on 2011-10-14
Last Modified: 2012-05-12
Hello, with the attached code I'm populating a gridview that resides in another gridview with pictures from a folder on my site. The code does work and the gridveiw is populated with the filenames of the pictures. The problem is that the path to the images does not work when using the name attribute of the fileinfo. It is just the name of the image.

With my attached code how can I make it so the image path is added to the name attribute of the fileinfo?
Here is the pictures gridview that resides in the parent gridview:
                          <asp:GridView runat="server" ID="gvPictures" AutoGenerateColumns="false">
                                                    <asp:Image runat="server" ID="ImgSurveyPicture" ImageUrl='<%# Eval("Name") %>' AlternateText="CWT - Survey Image" />


Here is the code that runs in the rowdatabound of the parent gridview to find the correct pictures and populat the pictures gridview:

            'get controls to work with
            Dim Pictures As LinkButton = e.Row.FindControl("lbPictures")
            Dim Field As Label = e.Row.FindControl("lblField")
            Dim Area As Label = e.Row.FindControl("lblArea")
            Dim gvPictures As GridView = e.Row.FindControl("gvPictures")

            'create unique key that is also the folder name for the items pictures
            Dim Item As String = (Field.Text & " - " & Area.Text)

            'get path to the pictures
            Dim PicturesPath As String = ("~/SurveyImages/Survey - " & lblViewSurveyNumber.Text & "/" & Item)

            Dim file() As FileInfo

            Dim DirInfo As New DirectoryInfo(Server.MapPath(PicturesPath))
            Dim path As String = (Server.MapPath(PicturesPath))

            If DirInfo.Exists Then
                'fill the file array with the fileinfo, populate the gridview and show the pictures button if pictures exists for the item
                file = DirInfo.GetFiles()

                gvPictures.DataSource = file

                If file.Count > 0 Then
                    Pictures.Visible = True
                    Pictures.Visible = False
                End If

            End If

Open in new window

Question by:gogetsome
    1 Comment
    LVL 74

    Accepted Solution


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    758 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

    14 Experts available now in Live!

    Get 1:1 Help Now