Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Populating a ListBox with list of files in a folder

Populating a ListBox with list of files in a folder

Scheduled Pinned Locked Moved ASP.NET
helpsysadmintutorialquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    naglbitur
    wrote on last edited by
    #1

    Hi. I am wondering how I can get a list of files in a folder on the server to appear on a webpage. I don´t know how to get the contents of a folder into a ListBox. Is there perhaps some other webcontrol that is better suited for this? This code I put in the Page_Load event: DirectoryInfo di = new DirectoryInfo(@"c:\somefoldername"); FileInfo [] fi = di.GetFiles(); foreach (FileInfo fiTemp in fi) ListBox1 By looking at the code you can see where I am stuck. Can someone please help me? Best regards, F

    M 1 Reply Last reply
    0
    • N naglbitur

      Hi. I am wondering how I can get a list of files in a folder on the server to appear on a webpage. I don´t know how to get the contents of a folder into a ListBox. Is there perhaps some other webcontrol that is better suited for this? This code I put in the Page_Load event: DirectoryInfo di = new DirectoryInfo(@"c:\somefoldername"); FileInfo [] fi = di.GetFiles(); foreach (FileInfo fiTemp in fi) ListBox1 By looking at the code you can see where I am stuck. Can someone please help me? Best regards, F

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      Hi there. Here is an example of populating a ListBox with file names[^].

      N 1 Reply Last reply
      0
      • M Mike Ellison

        Hi there. Here is an example of populating a ListBox with file names[^].

        N Offline
        N Offline
        naglbitur
        wrote on last edited by
        #3

        Thanks for your help. I pasted the code you pointed out into my code in VS 2005 and I got a bunch of errors that don´t seem to make sense. Is there a difference between VS 2003 and VS 2005 how this is done. Here is what I did and get loads of errors: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { public string FileName; //set directory and array Directory myDirectory; ArrayList values = new ArrayList(); //get files String [] files = Directory.GetFiles(@"N:\Myndir","*"); //iterate through list, replace path info, and add to the listbox //with the Add method. for(int i=0;i

        M 1 Reply Last reply
        0
        • N naglbitur

          Thanks for your help. I pasted the code you pointed out into my code in VS 2005 and I got a bunch of errors that don´t seem to make sense. Is there a difference between VS 2003 and VS 2005 how this is done. Here is what I did and get loads of errors: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { public string FileName; //set directory and array Directory myDirectory; ArrayList values = new ArrayList(); //get files String [] files = Directory.GetFiles(@"N:\Myndir","*"); //iterate through list, replace path info, and add to the listbox //with the Add method. for(int i=0;i

          M Offline
          M Offline
          Mike Ellison
          wrote on last edited by
          #4

          What errors did you get?

          N 1 Reply Last reply
          0
          • M Mike Ellison

            What errors did you get?

            N Offline
            N Offline
            naglbitur
            wrote on last edited by
            #5

            Hi. I got a bunch of strange errors but I think there must have been something wrong with the VS 2005 I am using because everything works very well in my VS 2003. It´s strange. Thanks very much for your help! By the way, you wouldn´t happen to know of some simple way of making an app stop working after a period of time. I finished making an app and I want it to only work until some day. It´s doesn´t have to be a bulletproof way as long as it is simple and works most of the time. I was thinking of perhaps making a thread that checks to see, for instance, if the year is 2007 and then it will disable some part (like the menus) of the app. How is this done if it is possible to do it this way. Thank you, F

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups