0

I'm writing a custom file-browser in WPF that used Windows Search Service to search files from the system. I followed the syntax for file search that is written here and here. But when I run the program an exception is raised with the following message:

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll Additional information: Unspecified error: -2147219688(0x80040718)

Here's the code that I'm using for file search:

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

string query = @"SELECT System.ItemName FROM SystemIndex " +
    @"WHERE SCOPE = 'file:O:/Design/_Revit Standards/Latest/Revit 2017 - Families' AND System.ItemName LIKE 'a%'";

OleDbCommand command = new OleDbCommand(query, connection);
connection.Open();


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

}
connection.Close();

Would really appreciate if someone helps me with this error.

rene
  • 41,474
  • 78
  • 114
  • 152
Ali Asad
  • 1,235
  • 1
  • 18
  • 33
  • Is that O: drive mapped to a server? Can you try with a local folder like C:/Users or so to see if the code works in that case. Then you know if the scope is causing the problem. – rene Jan 22 '18 at 07:01
  • Yes, 'O' is a network drive that I'm accessing. However I also have local 'E' drive which raises the same exception.. Am I missing something @rene ? – Ali Asad Jan 22 '18 at 07:02
  • 1
    Hmm, okay. The scope was something that jumped at me so that is why i asked. I don't know what is wrong then. – rene Jan 22 '18 at 07:04
  • @rene code is working fine with the 'C' drive path. Is there any syntax to perform the search on a network drive? – Ali Asad Jan 22 '18 at 07:04
  • 1
    I never tried but with the right permissions and if the server is running search as well you might try `file://servername/C:/path/on/server` – rene Jan 22 '18 at 07:09

0 Answers0