0

我正在尝试编写一个 WinForms 应用程序,该应用程序允许搜索包含在文本框中写入的字符串的文件(按 WIN+F,你明白了;))在这个应用程序中,有一个文件和目录列表,必须是搜索此字符串

我认为这些文件主要是 .doc 和 .xls,在 doc 中搜索可能更容易,但是在 Excel 文件中,单元格可以有不同的编码,我试图通过在 Notepad++ 中打开它们来“读取”这些文件,我发现只有拉丁字符的单元格很容易找到,但波兰字符的单元格有两个字节编码

在内置搜索的windows中,没有问题,它能够告诉,在一些测试文件中有我的字符串包含波兰特殊字符

所以我的问题基本上是,如果有一种方法可以为我的应用程序使用这个 Windows 内置搜索引擎(正如我所写,我只需要找到文件名),或者你有任何其他想法,我怎么能写一个简单的多文件搜索?

4

3 回答 3

0

您可以在代码中与 windows 搜索进行交互,使其能够完成搜索多种文件类型的繁重工作。有关详细信息,请参阅此 MSDN 文章:

http://msdn.microsoft.com/en-us/library/bb266517%28v=VS.85%29.aspx

于 2011-03-23T19:26:30.490 回答
0

您可能想要使用Windows Search SDK

于 2011-03-23T19:26:56.190 回答
0

查看此网站以了解如何使用Windows 索引 API。它指的是 ASP.NET,但代码是用 C# 编写的。

片段如下:

            string  QueryText = "asp alliance"; //The search string
            string CatalogName = "searchcatalog"; //The name of your Index Server catalog
            int NumberOfSearchResults = 0;  
            DataSet SearchResults = new DataSet();  

            //Prevent SQL injection attacks - further security measures are recommended  
            QueryText = QueryText.Replace("'", "''");  

            //Build the search query  
            string SQL = "SELECT doctitle, vpath, Path, Write, Size, Rank ";  
            SQL += "FROM \"" + CatalogName + "\"..SCOPE() ";  
            SQL += "WHERE";  
            SQL += " CONTAINS(Contents, '" + QueryText + "') ";  
            SQL += "AND NOT CONTAINS(Path, '\"_vti_\"') ";  
            SQL += "AND NOT CONTAINS(FileName, '\".ascx\" OR \".config\" OR \".css\"') ";  
            SQL += "ORDER BY Rank DESC";  

            //Connect to Index Server and perform search query  
            try   
            {  
                OleDbConnection IndexServerConnection = new OleDbConnection("Provider=msidxs;");  
                OleDbCommand dbCommand = new OleDbCommand(SQL, IndexServerConnection);  

                OleDbDataAdapter IndexServerDataAdapter = new OleDbDataAdapter();  
                IndexServerDataAdapter.SelectCommand = dbCommand;  

                IndexServerDataAdapter.Fill(SearchResults);  
                NumberOfSearchResults = SearchResults.Tables[0].Rows.Count;  
            }  
            catch (Exception ExceptionObject)  
            {  
                //Query failed so display an error message  
                NumberOfSearchResults = 0;  
                LabelNumberOfResults.Text = "Problem with retrieving search results due to: " + ExceptionObject.Message;  
                DataGridSearchResults.Visible = false;  

            }  
于 2011-03-23T19:28:45.480 回答