中的術語創建保存的搜索(.search-ms)是否存在一些C#代碼,用於按照與ISearchQueryHelper相同的方式在資源管理器搜索框中輸入的搜索術語中創建保存的查詢文件(.search-ms)將搜索條件擴展到Windows Search API的OLEDB查詢中?或者將OLEDB查詢轉換爲.search-ms文件的代碼?我想在資源管理器中顯示Windows搜索的結果 - 我可以在網格中顯示OleDb查詢結果,但更願意使用資源管理器。從資源管理器搜索框
0
A
回答
0
原來,創建保存的搜索並運行它並不是啓動顯示過濾結果的Windows /文件資源管理器窗口的最簡單方法,因爲保存的搜索XML非常複雜以編程方式生成。將搜索框左側的框內容作爲URL並將其提供給Internet Explorer將提供正確的結果。
文件夾
C:\Users\Simon\Pictures\iPhoneSample
在輸入搜索字符串
name:~ "*[*2602_Australia_Australian Capital Territory_Downer*].*" OR name:~ "*[*2602_Australia_Australian Capital Territory_O'Connor*].*"
後顯示預期的結果。點擊顯示「搜索中iPhoneSample結果」左手框顯示:
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
提供此作爲URL來互聯網瀏覽器(iexplore.exe的,而不是Explorer.exe中)顯示了一個新的Windows /文件,瀏覽器窗口預期的搜索結果。這樣做的某些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);
}
顯示搜索結果之後,窗口需要顯示後續搜索結果之前被關閉,否則隨後的結果不顯示。這可以用下面的代碼來完成:
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);
相關問題
- 1. 從excel超級鏈接中打開資源管理器搜索
- 2. 資源管理器
- 3. Eclipse:在項目資源管理器中搜索文件夾和資源
- 4. 如何用TFS團隊資源管理器搜索項目?
- 5. Windows10 Windows資源管理器的文件搜索的麻煩
- 6. 解決方案資源管理器中的搜索選項
- 7. 在Windows資源管理器中顯示Windows搜索結果
- 8. 搜索文件與Windows資源管理器
- 9. Visual Studio「搜索解決方案資源管理器」已禁用
- 10. Visual Studio 2012解決方案資源管理器搜索不搜索cshtml文件
- 11. 如何從資源管理器PSSession VM?
- 12. NetBeans項目的從資源管理器
- 13. DragNDrop從Java到Windows資源管理器
- 14. 從Silverlight打開Windows資源管理器
- 15. 從WSL啓動資源管理器
- 16. 從C控制Windows資源管理器#
- 17. 從ANT啓動Windows資源管理器?
- 18. Coherence資源管理器
- 19. 在Windows資源管理器
- 20. PyDev包資源管理器
- 21. Azure資源管理器
- 22. 在Windows資源管理器
- 23. 資源管理器集成
- 24. Eclipse CVS資源管理器
- 25. 資源管理
- 26. 在VS 2015中搜索文件名或DLL - 源代碼管理資源管理器
- 27. Android中的文件資源管理器像Windows資源管理器
- 28. VS代碼 - 文件資源管理器/資源管理器更改案例
- 29. TFS項目在源代碼管理資源管理器中可見,但不在團隊資源管理器中?
- 30. Lucene搜索管理器