Using the Windows API Code Pack I wrote this code here (in C#), using the Windows Search.
How to display this result in Windows Explorer (where it should be displayed)?
// create the leaf condition for the file name
SearchCondition fileNameCondition =
SearchConditionFactory.CreateLeafCondition(
SystemProperties.System.FileName, textBox2.Text,
SearchConditionOperation.Equal);
// create the search folder
ShellSearchFolder searchFolder = new ShellSearchFolder(fileNameCondition(ShellContainer)NonFileSystemKnownFolder.FromParsingName(@>"C:\Users\ILIANHOME\Downloads"));
Simple right? Not for me, I'm a pretty novice programmer, thanks in advance for any help:)
Search looks in all folders and subfolders within the library or folder you're viewing. When you tap or click inside the search box, the Search Tools tab appears. As you enter your search terms, your results will start to appear with your search terms highlighted.
Open File Explorer and enter a sample search query in the search box. Now, press the Enter key or click on the arrow located at the right end of the search bar, and then the search tab will show up in the ribbon. Press the Enter Key After Entering the Search Query to Bring Out the Search Tab.
Save a SearchIn the desktop, click or tap the File Explorer button on the taskbar. Open an Explorer window in the location where you want to search. Click or tap in the Search box, specify the criteria you want, and then perform the search. Click or tap the Save search button on the Search tab.
If it is just a single file, you can right click the file and open path location. Then, in the new location, click the explorer bar once and it will show the full path.
Unfortunately this doesn't seem to be a need that the Windows API Code Pack was designed to meet. That library is all about taking shell concepts and bringing them into managed code. At the API level, it is technically independent of the "real" Windows shell, such that it could be implemented using a different data provider than the actual COM shell APIs. With that goal in mind, the ability to "go back" to the native shell is difficult, as there may not be a native shell to go back to (speaking hypothetically of course; I don't know of anyone making an alternative implementation). In this regard, the library seems to think of itself as an extension of the Framework Class Library (which is probably valid, since some of the features -- like JumpList
-- did eventually make it into the core libraries).
Note that I can't speak for the authors of the library, the above is purely speculation based on the structure of the library and my experience with other .NET libraries from Microsoft. But whatever the reason, this functionality doesn't seem to exist.
What does exist is the ability to create your own Explorer window, through the ExplorerBrowser
control (or the WPF wrapper of it). See the ExplorerBrowser
sample that comes with the library for an example of that. I can't say that I recommend trying to imitate Explorer, though, even with these helpers.
For your particular problem of launching the search window, I would recommend looking into the search: protocol and see if it meets your needs. It doesn't have a nice object model to represent the queries, so you'd have to either make one yourself (or find one, it may exist) or just work with strings. But it is very flexible.
Your particular problem as above could be implemented as:
string folder = Uri.EscapeDataString(@"C:\Users\ILIANHOME\Downloads");
string file = '"' + Uri.EscapeDataString(textBox2.Text) + '"';
string uri = "search:query=filename:" + file + "&crumb=location:" + folder;
Process.Start(new ProcessStartInfo(uri));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With