I'm working on an application, an user can search for files or folders either on the local computer or on the network. I am using DirectoryInfo.GetDirecotories().
(a) But I also want to add the functionality that windows 7 uses for searching, I believe that uses indexing. I also saw "Windows Searching Service" on msdn, but I'm not sure which way is best, querying the indexed catalog or using the search service, any suggestions ? (b) I was wondering if any one can give me a small example in C# that searches the indexed catalog.
Thanks in advance.
See the below example:
It's using OLE DB api to connect to the indexer service and use a SQL-like syntax to search
System
objects in itsSystemIndex
table. You have 4 example queries which do different things. All example queries will search in thec:\
folder for items that containTest
in their names.You can search for files, folders mails and possibly other media (depending on OS) on local or other machines. From what I have researched network drives are not supported since they can't be indexed but you can connect to other machines for which I assume RPC is used in the background which means you have to supply network credentials using a different api (e.g. System.Net).
Note that for any of this to work your indexing must be fully operational on the target machine (which it is by default). The api is corresponding to whatever you specify in your Indexing Options. This is the screen in question:
The full list of properties for the
System
object can be found here: Property System Reference. This object contains things such as URL, Path, Name, Date etc.More interesting examples using different predicates (e.g.
scope
anddirectory
) can be found here: Windows Vista Search Syntax. There is also a crude MSDN documentation: SCOPE and DIRECTORY PredicatesI recommend you check out the documentation because you can do a lot of stuff with this api.