Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display a Windows Search result in Windows Explorer

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:)

like image 763
Ilian Vasilev Kulishev Avatar asked Mar 31 '13 21:03

Ilian Vasilev Kulishev


People also ask

What happens when you search Windows in File Explorer?

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.

How do I add a search to ribbon in File Explorer?

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.

How do I save search results in Windows Explorer?

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.

How do I view the full path in search results?

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.


1 Answers

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));
like image 199
Jacob Avatar answered Oct 03 '22 16:10

Jacob