如何实现多关键字搜索以从Web服务器进行搜索 [英] how to implement multi keyword search to search from a web server
本文介绍了如何实现多关键字搜索以从Web服务器进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hai all
我已经实现了单词搜索....
现在我需要使用多词搜索...
我需要在服务器中搜索文件...
使用单个单词键搜索文件的代码如下:
hai all
i had implemented single word search....
now i need to work with multi word search...
i need to search files in server...
code for searching files using single word key is as follows:
string s = "", s1 = ""; //to get the file name
// string files = "";
string filename = "*" + tb_search.Text + "*";
DirectoryInfo MyDir;
ArrayList CellarList = new ArrayList();
MyDir = new DirectoryInfo(Server.MapPath("files/"));
string path = (Server.MapPath("files/"));
//FileInfo[] MyFiles = MyDir.GetFiles("*.*");
string[] fileList = System.IO.Directory.GetFiles(path, filename);
foreach (string file in fileList)
{
if (file.ToLower().Contains(tb_search.Text.ToLower().ToString()))
{
s = file.ToString();
s1 = s.Replace(path, "");
lb_search.Items.Add(s1);
}
}
谁能帮我...
在此先感谢
can any one help me...
thanks in advance
推荐答案
根据您的代码,您正在尝试在给定目录中搜索文件名.,
为此,您可以使用以下代码.
As per your code, you are trying to search the file names in the given directory .,
for this you can use the below code.
string[] files = Directory.GetFiles(Server.MapPath("files/"), "*.*");
第二个参数可以是任何通配符.
例如:
Second Argument can be any wild card.
Ex :
string[] files = Directory.GetFiles(Server.MapPath("files/"), "A*.*");
文件以"A"开头
files start with "A"
string[] files = Directory.GetFiles(Server.MapPath("files/"), "ABC?.*");
文件以"ABC"开头,并以任何字符结尾.
Files Start with "ABC" and ends with any character.
string[] files = Directory.GetFiles(Server.MapPath("files/"), "ABC DEF*.*");
文件以"ABC DEF"开头,并以任何字符结尾.
希望对您有帮助.
Files Start with "ABC DEF" and ends with any characters.
Hope this helps you.
这篇关于如何实现多关键字搜索以从Web服务器进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文