wpf c#+ 3.5框架+在Windows文件系统中搜索文件中的特定关键字 [英] wpf c# + 3.5 framework + seraching particular key word in file in windows file system

查看:145
本文介绍了wpf c#+ 3.5框架+在Windows文件系统中搜索文件中的特定关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含很多文件的文件夹,例如doc,excel,ppts等.一旦用户从组合中选择类别,我便会分配与特定选择相关的关键字.现在,我的wpf应用程序必须搜索关键词,然后搜索与关键词匹配的文件的整个文件夹和内容,并在gridview中显示匹配的文件.速度和性能也必须保持

Kinldy请求某人帮助我.

I have a folder with lot of files like doc,excel,ppts etc.. once the user selects a catagory from the combo i have assigned key words related to the particular selection. Now w.r.t to the key words my wpf application has to search the entire folder and content of the files which are matching to key words and display the matching files in a gridview. Speed and performance also has to be maintained

Kinldy request someone to help me.

推荐答案

在此处查看我的文章: ^ ]
Check my article here : hOOt - full text search engine[^]


您要做的绝对不是一件小事.您应该看一下这些文章,以帮助自己起步

在C#中使用IFilter [ C#搜索引擎:重构为搜索Word,PDF等 [
What you are trying to do is most definitely not a trivial task. You should take a look at these articles to give yourself a head start

Using IFilter in C#[^]

C# search engine: refactored to search Word, PDF and more[^]

Good luck


List< string> MyKeyWords = GetKeywords();
var allDirectories = new DirectoryInfo("Path").GetDirectories("*",SearchOption.AllDirectories);
lstView.ItemsSource =(来自di.GetFiles("*.txt")中fi的allDirectories中的di,其中HasKeyWordMatch(fi,MyKeyWords)选择fi);


私人布尔HasKeyWordMatch(FileInfo fi,List< string> MyKeyWords)
{
试试
{
StreamReader testTxt =新的StreamReader(fi.FullName);
字符串allRead = testTxt.ReadToEnd();
testTxt.Close();
字符串regMatch ="string";
如果(Regex.IsMatch(allRead,regMatch))
{
返回true;

}
其他
{
返回false;
}


}
catch(ex ex例外)
{
返回false;
}
}
List<string> MyKeyWords = GetKeywords();
var allDirectories = new DirectoryInfo("Path").GetDirectories("*", SearchOption.AllDirectories);
lstView.ItemsSource = (from di in allDirectories from fi in di.GetFiles("*.txt") where HasKeyWordMatch(fi, MyKeyWords) select fi);


private bool HasKeyWordMatch(FileInfo fi, List<string> MyKeyWords)
{
try
{
StreamReader testTxt = new StreamReader(fi.FullName);
string allRead = testTxt.ReadToEnd();
testTxt.Close();
string regMatch = "string";
if (Regex.IsMatch(allRead, regMatch))
{
return true;

}
else
{
return false;
}


}
catch (Exception ex)
{
return false;
}
}


这篇关于wpf c#+ 3.5框架+在Windows文件系统中搜索文件中的特定关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆