I set listbox.datasource to fileinfo() object, but no files appear in the listbox.

Discussion in 'ASP .Net' started by COHENMARVIN, Oct 14, 2005.

  1. COHENMARVIN

    COHENMARVIN Guest

    I am trying to display the contents of a directory in a listbox. I
    manage to get an array of fileInfo objects, and when I print them out
    they indeed contain several file names. But when I do
    'imgBanner.DataSource = fileInfos', I'm left with an empty listbox.
    Here is the code:
    =========================
    Dim fileInfos() as FileInfo
    Dim fi as FileInfo

    myDir = New DirectoryInfo(MapPath("/vwSpecials"))
    fileInfos = myDir.GetFiles()

    For Each fi In fileInfos
    strFiles = strFiles & "," & fi.Name
    Next
    LabDiagnostic.Text = strFiles
    imgBanner.DataSource = fileInfos
    ===============================
    The actual control is:
    <ASP:Listbox id="imgBanner" runat="server" Rows="1" />

    Any help is appreciated.
    -- Marvin
     
    COHENMARVIN, Oct 14, 2005
    #1
    1. Advertising

  2. RE: I set listbox.datasource to fileinfo() object, but no files appear

    well, have you got a line imgBanner.DataBind();
    after imgBanner.DataSource = fileInfos; ?

    or just omitted it in the question?


    "COHENMARVIN" wrote:

    > I am trying to display the contents of a directory in a listbox. I
    > manage to get an array of fileInfo objects, and when I print them out
    > they indeed contain several file names. But when I do
    > 'imgBanner.DataSource = fileInfos', I'm left with an empty listbox.
    > Here is the code:
    > =========================
    > Dim fileInfos() as FileInfo
    > Dim fi as FileInfo
    >
    > myDir = New DirectoryInfo(MapPath("/vwSpecials"))
    > fileInfos = myDir.GetFiles()
    >
    > For Each fi In fileInfos
    > strFiles = strFiles & "," & fi.Name
    > Next
    > LabDiagnostic.Text = strFiles
    > imgBanner.DataSource = fileInfos
    > ===============================
    > The actual control is:
    > <ASP:Listbox id="imgBanner" runat="server" Rows="1" />
    >
    > Any help is appreciated.
    > -- Marvin
    >
    >
     
    =?Utf-8?B?U3JlZWppdGggUmFtKE1DU0QuTkVUKQ==?=, Oct 14, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Antonio

    Problem creating FileInfo Array

    Antonio, Nov 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,799
    Maqsood Ahmed
    Dec 17, 2004
  2. Do
    Replies:
    1
    Views:
    2,133
    srinivas moorthy
    Dec 1, 2003
  3. Craig Douglas

    Ordering FileInfo[] by date

    Craig Douglas, Jan 30, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    366
    Craig Douglas
    Jan 30, 2004
  4. Martin Dechev
    Replies:
    0
    Views:
    577
    Martin Dechev
    Apr 2, 2004
  5. =?Utf-8?B?bWF2cmljazEwMQ==?=

    FileInfo Object Crashing??

    =?Utf-8?B?bWF2cmljazEwMQ==?=, Apr 27, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    314
    =?Utf-8?B?bWF2cmljazEwMQ==?=
    Apr 27, 2005
Loading...

Share This Page