如何实现多关键字搜索以从Web服务器进行搜索 [英] how to implement multi keyword search to search from a web server
本文介绍了如何实现多关键字搜索以从Web服务器进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我已经实现了单个单词搜索,现在我需要使用多个关键字搜索..
我需要在服务器中搜索文件...
使用单个单词键搜索文件的代码如下:
Hi all,
I had implemented single word search, now I need to work with multiple key-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
推荐答案
看看这可能对您有帮助:
http://www.asp.net/web-页面/教程/文件,图像,和媒体/与文件一起工作 [在ASP中读取文件以及如何在特定目录下的所有文件中搜索特定文本. [ ^ ]
================================================== ==============
试试这个:
Look at this it may help you:
http://www.asp.net/web-pages/tutorials/files,-images,-and-media/working-with-files[^]
Reading Files in ASP and How to Search for a particular text in all files in a specific directory.[^]
=================================================================
try this:
.aspx file
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>
.cs file
protected void Button1_Click(object sender, EventArgs e)
{
ListBox1.Items.Clear();
DirSearch("c:\\test");
}
void DirSearch(string sDir)
{
foreach (string d in Directory.GetDirectories(sDir))
{
foreach (string f in Directory.GetFiles(d, TextBox1.Text))
{
ListBox1.Items.Add(f);//if find the file, then put it into the listbox
}
DirSearch(d);
}
}
也可以尝试以下链接:
http://www.4guysfromrolla.com/articles/052803-1.aspx [ ^ ]
try this link also:
http://www.4guysfromrolla.com/articles/052803-1.aspx[^]
这篇关于如何实现多关键字搜索以从Web服务器进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文