EnumerateFiles

I have a windows forms ap that will be for indexing file collections. I am using the .net DirectorySearcher, which implements an UnauthorizedAccessException. Problem with the following code is, the exception actually occurs within the foreach statement, so when an exception is thrown, the loop stops processing. How can I catch the exception and keep the loop working? Should I keep a counter and tell it to start at the next position from the last position after it catches the exception repeating this until it's finished? Here's the code in question:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
var thelist = Directory.EnumerateFileSystemEntries(FB.SelectedPath, "*", SearchOption.AllDirectories);
                List<String> strList = new List<String>();
                try
                {
                    foreach (var entry in thelist)
                    {
                        try
                        {
                            strList.Add(entry.ToString());
                        }
                        catch (UnauthorizedAccessException) { }
                    }
                }
                catch (UnauthorizedAccessException) { }
Topic archived. No new replies allowed.