Click here to Skip to main content
15,947,411 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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, "");

Can any one help me...
Thanks in advance
Updated 15-Jan-12 21:23pm

1 solution

Look at this it may help you:,-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)
    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


try this link also:[^]
Share this answer
Emad Al Hawary 16-Jan-12 3:31am
Ragi Gopi 16-Jan-12 3:44am    
am not asking about how to list files......

i want to know how to search per the key word in the textbox...

that is now i am extracting files by one key word i need to use multile key word search as in google......(but from my server)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900