C# 从资源管理器搜索框中的术语创建保存的搜索(.search ms)
是否有一些C#代码用于从浏览器搜索框中输入的搜索词创建保存的查询文件(.search ms),其方式与ISearchQueryHelper将搜索词扩展为Windows search API的OLEDB查询的方式相同?或用于将OLEDB查询转换为.search ms文件的代码?我想在资源管理器中显示Windows搜索的结果-我可以在网格中显示OleDb查询结果,但更喜欢使用资源管理器 结果表明,创建保存的搜索并运行它不是启动显示筛选结果的Windows/File explorer窗口的最简单方法,因为保存的搜索XML非常复杂,无法通过编程方式生成。将搜索框左侧框中的内容作为URL,并将其提供给Internet Explorer,将得到正确的结果 输入搜索字符串后C# 从资源管理器搜索框中的术语创建保存的搜索(.search ms),c#,search,C#,Search,是否有一些C#代码用于从浏览器搜索框中输入的搜索词创建保存的查询文件(.search ms),其方式与ISearchQueryHelper将搜索词扩展为Windows search API的OLEDB查询的方式相同?或用于将OLEDB查询转换为.search ms文件的代码?我想在资源管理器中显示Windows搜索的结果-我可以在网格中显示OleDb查询结果,但更喜欢使用资源管理器 结果表明,创建保存的搜索并运行它不是启动显示筛选结果的Windows/File explorer窗口的最简单方法,
name:~ "*[*2602_Australia_Australian Capital Territory_Downer*].*" OR name:~ "*[*2602_Australia_Australian Capital Territory_O'Connor*].*"
在文件夹中
C:\Users\Simon\Pictures\iPhoneSample
显示了预期的结果。单击左侧显示“iPhoneSample中的搜索结果”的框显示:
将此作为URL提供给Internet Explorer(iexplore.exe而不是Explorer.exe)将显示一个新的Windows/File Explorer窗口,其中包含预期的搜索结果。用于执行此操作的一些C#代码如下所示:
/// <summary>
/// Show Windows Explorer in new window with results filtered by search string
/// </summary>
/// <param name="sCommonFolder">Folder to search in </param>
/// <param name="sSearchString">search string</param>
private void ShowSearchResultsInExplorer(string sCommonFolder, string sSearchString)
{
// sCmd = "search-ms:displayname=Search%20Results%20in%20iPhoneSample&crumb=name" & _
//"%3A~""*[*2602_Australia_Australian%20Capital%20Territory_Downer*].*""%20OR%20name%3A~""" & _
//"*[*2602_Australia_Australian%20Capital%20Territory_O'Connor*].*""&crumb=location:C%3A%5CUsers%5CSimon%5CPictures%5CiPhoneSample"
string sFilter = "search-ms:displayname=";
sFilter += Uri.EscapeDataString("Tagged files in " + sCommonFolder);
sFilter += @"&crumb=" +sSearchString;
sFilter += @"&crumb=location:" + Uri.EscapeDataString(sCommonFolder);
Process.Start("IExplore.exe", sFilter);
}
此代码需要一些声明:
using System.Web;
using System.Runtime.InteropServices;
....
static uint WM_CLOSE = 0x10;
...
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
foreach (SHDocVw.InternetExplorer window in shellWindows)
{
Console.Write ("Window " + window.LocationName + " " + window.LocationURL + " " + window.Name + " " + window.HWND + "\r\n");
if (window.LocationName.Contains("Tagged files"))
{
SendMessage((IntPtr)window.HWND, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
}
}
using System.Web;
using System.Runtime.InteropServices;
....
static uint WM_CLOSE = 0x10;
...
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);