
-----------------------------------
rar
Wed Jun 30, 2010 9:56 am

Visual C# Question: Display Folder Contents On Form
-----------------------------------
So evolving from my last question, I have another question about folder display.

How can I get the folder contents to display on the screen? I'm not sure which tool to use for this, but I'm sure I have to use the path name somehow...

-----------------------------------
Zren
Wed Jun 30, 2010 6:36 pm

Re: Visual C# Question: Display Folder Contents On Form
-----------------------------------
What do you mean by contents? Like in the folderDialog? Or just a list of files with their paths in a list? For the latter, Use Directory.


string source = "C:\\Blarg";
string

Bear in mind, I'm also new to C# so there's could be other/better ways.

-----------------------------------
rar
Wed Jun 30, 2010 7:53 pm

RE:Visual C# Question: Display Folder Contents On Form
-----------------------------------
[code]string[] dirEntries = Directory.GetDirectories(source);
            foreach (string dirName in dirEntries)
            {
                textBox1.Lines[count] = Path.GetFileName(dirName);
                if (count != dirEntries.Length - 1)
                {
                    count++;
                }
            }
[/code]
Why am I running out of the array??? I don't know of any other way to print on different Lines in the textbox...

-----------------------------------
Zren
Wed Jun 30, 2010 9:33 pm

RE:Visual C# Question: Display Folder Contents On Form
-----------------------------------
Both are string[]. I'll save ya some brainwaves.

textBox1.Lines = dirEntries;

As for your logic, I'm guessing it's because you didn't initialize textBox1.Lines' size meening it's still the length it was from the begining (empty) so there's your out of bounds error.

textBox1.Lines = new string[dirEntries.Length];
