Around and About .NET World

Il blog di Marco Minerva
posts - 1671, comments - 2232, trackbacks - 2135

My Links

News

Contattami su Live Messenger:


MCTS: Windows, Web, Distributed Applications & SQL Server

MCPD: Enterprise Applications

Tag Cloud

Archives

Post Categories

Links

Integrare Windows Vista Search nelle proprie applicazioni

Windows Vista espone il proprio motore di ricerca integrato come database, cosicché è possibile accedere ad esso attraverso una normale connessione di tipo OleDb. Ad esempio:

public struct SearchResult { public string FileName; public string Url; public DateTime LastModified; public long Size; public string ItemType; } public ReadOnlyCollection<SearchResult> Search(string path, string pattern) { string connString = @"Provider=Search.CollatorDSO;Extended Properties='Application=Windows'"; string searchString = string.Format( @"SELECT System.FileName, System.ItemUrl, System.DateModified, System.Size, System.ItemType FROM SYSTEMINDEX WHERE Scope='file:{0}' AND System.FileName LIKE '{1}%'", path, pattern); List<SearchResult> result; using (OleDbConnection conn = new OleDbConnection(connString)) { conn.Open(); OleDbCommand cmd = new OleDbCommand(searchString, conn); using (OleDbDataReader reader = cmd.ExecuteReader()) { if (!reader.HasRows) return null; result = new List<SearchResult>(); object[] rows = new object[reader.FieldCount]; while (reader.Read()) { reader.GetValues(rows); SearchResult temp = new SearchResult(); temp.FileName = (string)rows[0]; temp.Url = (string)rows[1]; temp.LastModified = (DateTime)rows[2]; temp.Size = (long)rows[3]; temp.ItemType = (string)rows[4]; result.Add(temp); } } } return result.AsReadOnly(); }

Su questo blog sono disponibili maggiori informazioni su Windows Desktop Search e una serie di link di approfondimento.

Print | posted on Sunday, February 18, 2007 3:41 PM | Filed Under [ C# ]

Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET