2

I am working on a C# WPF project which can search files on specified directory paths. These paths can be on a local and on a remote machine as well, so I have to solve it on both.

At first I tried to use a query which has a local path, but the OleDbDataReader class returns with zero records. I am sure that I have adjusted everything on the corresponding way, e.g. Indexing Options contains the correct path: Indexing Options contains the correct path - or in file explorer: or in file explorer - and File Types contains txt file in the list: File Types contains txt file

Code to the local searching:

CSearchManager manager = new CSearchManager();
CSearchCatalogManager catalogManager = manager.GetCatalog("SystemIndex");
CSearchQueryHelper queryHelper = catalogManager.GetQueryHelper();
queryHelper.QuerySelectColumns = "System.ItemName,System.FileName,System.Author,System.ItemUrl,System.ItemType";
queryHelper.QueryWhereRestrictions = @"AND SCOPE='file:D:\testIndexing' AND System.FileName LIKE '*.txt'";
string userQuery = "SELECT System.FileName FROM SystemIndex WHERE SCOPE='file:D:\testIndexing' AND System.FileName LIKE '*.txt'";
string sqlQuery = queryHelper.GenerateSQLFromUserQuery(userQuery);

OleDbConnection conn = new OleDbConnection(queryHelper.ConnectionString);
conn.Open();
OleDbCommand command = new OleDbCommand(sqlQuery, conn);
using (OleDbDataReader reader = command.ExecuteReader())
{
    while (reader.Read())
    {
        Console.WriteLine(reader.GetString(0));
        Console.WriteLine(reader[0]);
    }
}
conn.Close();

Later I tried to connect to a Windows Server. The server path is correct because I can browse the server files via File Explorer - this is a VPN connection -. The Indexing Options are correctly adjusted here as well. But the problem is that I can not use the connection method above, because the GetCatalog methot is not supports the remote connection - so I tried THIS method. I found an example which can see below, but here I got an exeption like: System.UnauthorizedAccessException: 'Retrieving the COM class factory for remote component with CLSID {[CLSID]} from machine [SERVER NAME] failed due to the following error: 80070005 [SERVER NAME].'

The problem is when I tried to add the CLSID. I have no idea where can I get this ID because I didn't find any concrete solution for this. Here I want some help like what is the CLSID in my case, and how to get it?

Code to the remote searching:

Guid guid = new Guid("{[CLSID]}"); // this is what I don't know how to provide
Type managerType = Type.GetTypeFromCLSID(guid, "SERVER_NAME", true);
var comManager = Activator.CreateInstance(managerType);
CSearchManagerClass manager = (CSearchManagerClass)System.Runtime.InteropServices.Marshal.CreateWrapperOfType(comManager, typeof(CSearchManagerClass));

CSearchCatalogManager catalogManager = manager.GetCatalog("SERVER_NAME.SystemIndex");
CSearchQueryHelper queryHelper = catalogManager.GetQueryHelper();
queryHelper.QuerySelectColumns = "System.ItemName,System.FileName,System.Author,System.ItemUrl,System.ItemType";
queryHelper.QueryWhereRestrictions = @"AND SCOPE='file:\\SERVER_NAME\path\to\scope' AND System.FileName LIKE '*.txt'";

string userQuery = @"SELECT System.FileName FROM SystemIndex WHERE SCOPE='file:\\SERVER_NAME\path\to\scope' System.FileName LIKE '*.txt'";
string sqlQuery = queryHelper.GenerateSQLFromUserQuery(userQuery);

OleDbConnection conn = new OleDbConnection(queryHelper.ConnectionString);
conn.Open();
OleDbCommand command = new OleDbCommand(sqlQuery, conn);
using (OleDbDataReader reader = command.ExecuteReader())
{
    while (reader.Read())
    {
        Console.WriteLine(reader.GetString(0));
        Console.WriteLine(reader[0]);
    }
}
conn.Close();
Christian
  • 105
  • 1
  • 6

0 Answers0