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();
}