문제

I am looking for a code that gets results of full text search using Windows search (it should be available in Vista, 7 and 8 by default).

I have found some questions here and some texts on msdn, but none of them have some exact code that works. I have tried with Windows API Code Pack (as it is mentioned as one of the interfaces to Windows Search), but it returns results only for file names, not for full text.

도움이 되었습니까?

해결책

Here is the code that does work - in example I made it to search for the word "dummy" in the desktop folder:

string connectionString = "Provider=Search.CollatorDSO;Extended Properties=\"Application=Windows\"";
OleDbConnection connection = new OleDbConnection(connectionString);

string query = @"SELECT System.ItemName FROM SystemIndex " +
   @"WHERE scope ='file:" + System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "' and FREETEXT('dummy')";
OleDbCommand command = new OleDbCommand(query, connection);
connection.Open();

List<string> result = new List<string>();

OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
    result.Add(reader.GetString(0));
}

connection.Close();

다른 팁

Take a look at the DSearch example. Windows Search Code Samples

That's what you want.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top