We have a folder on our network that we want to search within, including subfolders, from our program. We want to return a list of files whose name contains "String1" or "String2" or "StringN". We would prefer to programmatically open an Explorer window and view all files that match the search results using the native windows file explorer.
Is this possible? How?
Thanks!
Since the Windows Explorer changes with every version of the OS ... I'd recommend doing the search via .NET and displaying the results on a grid on a form.
Use the System.IO namespace.
System.IO.Directory.GetFiles(folderName) will get the files ...
You will need a recursive function to enumerate all of the files first, then recurse each of the subdirectories.
Here is some code to create the saved search xml file (file.search-ms) for searches by name with specified path and search string:
The example code at https://github.com/nvuono/ExplorerQuickSearch uses searches by file extension only, but shows how to to create the saved search in temp folder and execute it.
An even better solution is to generate a URL for the search and supply it to Internet Explorer, which generates a Windows/File Explorer window showing the search results. Some code for doing this is shown at
Create a saved search (.search-ms) from terms in Explorer search box
You can use the .ms-search file format to express a saved search. If you open this file format it will launch a File Explorer with the search conditions applied.
If you already have a File Explorer window opened with a search applied, you can save that using the 'save search' button on the ribbon.