System.IO.Directory.GetFiles(string,string) enables you to provide a search pattern as the second argument.

I have a list of file extensions that I need to search for and discovered two issues with this method.

1. The second argument only accepts a single search pattern string, so I used the following code to resolve this:

    List<string> _searchPatternList = new List<string>();
    ...
    List<string> fileList = new List<string>();
    foreach ( string ext in _searchPatternList )
    {
        foreach ( string subFile in Directory.GetFiles( folderName, ext  )
        {
            fileList.Add( subFile );
        }
    }
    
    // Sort alpabetically
    fileList.Sort();

    // Add files to the file browser control    
    foreach ( string fileName in fileList )
    {
        ...;
    }

2. There is an 'anomaly' with search patterns. "*.htm" will match both .htm and .html files. To avoid duplicate file entries, you will need to remove all extensions that are equivalent:

   Dictionary<string,bool> extensionMap = new Dictionary<string,bool>(); // Initialized with ".htm", ".html", ".jpg", etc

   _searchPatternList.Clear();
   
   foreach ( string ext in extensionMap.Keys )
   {
       if ( ext.Length > 4 )
       {
           if ( !extensionMap.ContainsKey( ext.Substring( 0, 4 ) ) )
           { // No short version, so add to list
               _searchPatternList.Add( "*" + ext );
           }
        }
        else
        {
            _searchPatternList.Add( "*" + ext );
        }
   }