简体   繁体   中英

C# windows search on mapped network drive

I am trying to do a Windows Search on a mapped network drive from ac# .NET 3.5 web application. It works fine with a local drive.

I can map the drive and I can add that mapped drive to a library, and do an interactive search successfully from the Start menu. It finds files and even finds text within files. The drive is indexed on the server.

When I try to find a list of files for a folder within the mapped drive using code then nothing is returned. I am not sure what the folder needs to be in the search string as it is its presence within the library (Documents) that allows it to be searched.

System.Data.OleDb.OleDbConnection connection = new
System.Data.OleDb.OleDbConnection();
connection.ConnectionString = "provider=Search.CollatorDSO.1
EXTENDED?PROPERTIES='Application=Windows'";
        connection.Open();
string sqlString = @"SELECT System.ItemName FROM SystemIndex WHERE 
System.ItemType <> 'Directory' AND DIRECTORY='File:Z:\\'";
System.Data.OleDb.OleDbCommand cmd = new
System.Data.OleDb.OleDbCommand(sqlString, connection);
System.Data.OleDb.OleDbDataReader reader = null;
reader = cmd.ExecuteReader();
while (reader.Read())
{
    ...
}

Nothing is returned by the reader. The Z: drive is the mapped drive.

I can't add the mapped drive in Program Manager > Indexing Options. It isn't listed.

I solved the problem by adding the server name before 'SystemIndex' and in the share name in the SQL string as follows:

string sqlString = @"SELECT System.ItemName FROM MyServer.SystemIndex WHERE System.ItemType <> 'Directory' AND DIRECTORY='File://MyServer/MyShare/MyFiles'";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM