Reputation: 11
I'm beginner in C#, and I'm trying to search for files in subfolders and show them in a listbox. I have already tried this:
List<string> search = Directory.GetFiles("@C:\\", "*.*", SearchOption.AllDirectories).ToList();
A message from Visual Studio appears: An unhandled exception of type 'System.NotSupportedException' ocurred in mscorlib.dll.
What should I do?
Already grateful!
Upvotes: 0
Views: 224
Reputation: 5189
The @ symbol has to go before the double quotes. This indicates that you are not using escaping in the string that follows. When you use this, then you dont need to escape your backslashes. Try changing it to this.
List<string> search = Directory.GetFiles(@"C:\", "*.*", SearchOption.AllDirectories).ToList();
Upvotes: 1
Reputation: 7288
The NotSupportedException is the result of a bad path... Looks like you put the @ inside the quotes instead of outside.
Upvotes: 3
Reputation: 22721
Read the documentation: http://msdn.microsoft.com/en-us/library/ms127994(v=vs.110).aspx
NotSupportedException: A file or directory name in the path contains a colon (:) or is in an invalid format.
Upvotes: 1