I am having a list box on my form what i need is i would like to display all the text files that are presented in the local drives to that list box on Form Load can any one help me.
I wrote my code like this
string[] filepaths;
filepaths = Directory.GetFiles(@"c:\", "*.txt", SearchOption.AllDirectories);
But this is throwing an error how can i read the files from all directories
Something like this:
notice that a recursive walk of an entire drive can take a long time…
EDIT:
To avoid access denied problem, instead of
Directory.GetFiles()you can use the code given in this answer :