Here is some code to create the saved search xml file (file.search-ms) for searches by name with specified path and search string:
/// <summary>
/// Generates the XDocument needed to create a .search-ms file for the path and mask given where mask specifies name parameter.
/// search string in Windows is name:~searchmask. Searchmask includes * at beginning and end to find string present anywhere in name
///
/// </summary>
/// <param name="searchPath">absolute path eg C:\Pictures\</param>
/// <param name="searchMask"> part of search string after name:~</param>
/// <returns></returns>
public XDocument GenerateSearchDocName(string searchPath, string searchMask)
{
// "*[*2602_Australia_Australian Capital Territory_O'Connor*].*" - example searchMask
string str = @"<?xml version=""1.0""?><persistedQuery version=""1.0""><viewInfo viewMode=""icons"" iconSize=""96"" stackIconSize=""0"" displayName=""Search Results in iPhoneSample"" autoListFlags=""0""><visibleColumns><column viewField=""System.ItemNameDisplay""/><column viewField=""System.ItemDate""/><column viewField=""System.Keywords""/><column viewField=""System.Size""/><column viewField=""System.Rating""/><column viewField=""System.ItemFolderPathDisplay""/></visibleColumns><sortList><sort viewField=""System.Search.Rank"" direction=""descending""/><sort viewField=""System.ItemDate"" direction=""descending""/><sort viewField=""System.ItemNameDisplay"" direction=""ascending""/></sortList></viewInfo><query><conditions><condition type=""leafCondition"" property=""System.ItemNameDisplay"" operator=""matches"" propertyType=""string"" ";
str += @"value=" + searchMask ;
str+= @" localeName=""en-US""><attributes><attribute attributeID=""{9554087B-CEB6-45AB-99FF-50E8428E860D}"" clsid=""{C64B9B66-E53D-4C56-B9AE-FEDE4EE95DB1}"" chs=""1"" sqro=""585"" timestamp_low=""3078723010"" timestamp_high=""30601338""><condition type=""leafCondition"" property=""System.ItemNameDisplay"" operator=""matches"" propertyType=""string"" ";
str += @"value=" + searchMask;
str+= @" localeName=""en-US""><attributes><attribute attributeID=""{9554087B-CEB6-45AB-99FF-50E8428E860D}"" clsid=""{C64B9B66-E53D-4C56-B9AE-FEDE4EE95DB1}"" chs=""1"" sqro=""585"" timestamp_low=""2194097220"" timestamp_high=""30601338""><condition type=""leafCondition"" property=""System.ItemNameDisplay"" operator=""matches"" propertyType=""string"" ";
str += @"value=" + searchMask + " ";
str+= @"valuetype=""System.StructuredQueryType.Blurb"" localeName=""en-US""><attributes><attribute attributeID=""{9554087B-CEB6-45AB-99FF-50E8428E860D}"" clsid=""{C64B9B66-E53D-4C56-B9AE-FEDE4EE95DB1}"" chs=""0"" ";
str += @"parsedString=""name:~ "" + searchMask.TrimStart('"').TrimEnd('"') + @"""" ";
str+= @"localeName=""en-US"" timestamp_low=""2194097220"" timestamp_high=""30601338""/></attributes></condition></attribute></attributes></condition></attribute></attributes></condition></conditions><kindList><kind name=""item""/></kindList><scope>";
str+=@"<include path="""+ searchPath + @""" ";
str+=@"attributes=""1887437183""/></scope></query></persistedQuery>";
XDocument doc = XDocument.Parse(str);
return doc;
}
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